Javascript
React JS
1 Series learn ReactJs
https://youtube.com/playlist?list=PLyZUcCQtUmW3fuNX7IkaadGPwl2rnqMbZ
2 Action On JavaScript
3 Get Properties Child By relattive variable
4 Called function in javascript
1 use () in tag html
const callFunction = (row , event) {
// ... event.target.value
}
<button onClick={ (event) => { callFunction(row , event) } > clickRow </button>
2 use function
const callFunction = (row) => (event) {
// ... event.target.value
}
<button onClick={callFunction(row)> clickRow </button>
5 Copy Object
5.1 if datatype is primitive use =
let a = 10;
let b= a;
5.2 if is the object normal not contain object child use
Use the spread (...) syntax or Use the Object.assign() method Shallow copy first level.
const person = {
firstName: 'John',
lastName: 'Doe'
};
// using spread ...
let p1 = {
...person
};
// using Object.assign() method
let p2 = Object.assign({}, person);
5.3 // using JSON for deep level
let person = {firstName: 'John',
lastName: 'Doe',
address: {
street: 'North 1st street',
city: 'San Jose',
state: 'CA',
country: 'USA'
}
};
let p3 = JSON.parse(JSON.stringify(person));
reference: https://www.javascripttutorial.net/object/3-ways-to-copy-objects-in-javascript/
6 Copy array in Js
6.1 use spread [...] only boolean, number, and string. first level.
ex: [1,4,true,'string']
6.2 Literal structures [[], {}];
use JSON.parse(JSON.stringify(myArray))
ex: const type2 = [[], {}];
6.3 Array of prototype-objects (function)
ex: const type3 = [function () {}, function () {}];
Use cloneDeep of Lo-dash
7 Compare Object
7.1 If Object is primitive
let a = 10
let b = 10
use a === b // true
7.2 Object, new String, new Number, new Boolean.
Use JSON.stringify() good for String, Number, Boolean.
let a = new Number(4);
let a2 = a ;
let a3 = new Number(4);
a === a2 // true
a === a3 //false
JSON.stringify(a) === JSON.stringify(a3) //true
let a2 = a ;
let a3 = new Number(4);
a === a2 // true
a === a3 //false
JSON.stringify(a) === JSON.stringify(a3) //true
Use JSON.stringify() with object must order must same.
let a = { b: 11 , c:12}
let b = { b: 11 , c:12}
let c = { c:12 , b: 11} // mix updata
let b = { b: 11 , c:12}
let c = { c:12 , b: 11} // mix updata
JSON.stringify(a) === JSON.stringify(b) //true
JSON.stringify(a) === JSON.stringify(c) //false
if you must compare the order mix up use must code
function deepEqual(x, y) {
const ok = Object.keys, tx = typeof x, ty = typeof y;
return x && y && tx === 'object' && tx === ty ? (
ok(x).length === ok(y).length &&
ok(x).every(key => deepEqual(x[key], y[key]))
) : (x === y);
}
const ok = Object.keys, tx = typeof x, ty = typeof y;
return x && y && tx === 'object' && tx === ty ? (
ok(x).length === ok(y).length &&
ok(x).every(key => deepEqual(x[key], y[key]))
) : (x === y);
}
7.3 Use isEqual library Lodash
8 Compare Array
8.1 Use isEqual library Lodash
notice: must same order if not return false.
_.isEqual([1,2,3], [2,1,3]) => false
_.isEqual([1,2,3].sort(), [2,1,3].sort()) => true
instead of isEqual can use difference(). The difference() is not distinguish order.
_.difference([2, 1, 7], [2, 3]); // [1,7]
_.difference([3,2,1], [2, 3,1]); // []
9 Check Object null and undefied and empty (work for object)
https://sharecodefull.blogspot.com/2021/07/check-status-object.html
10 ES 6 some new features
https://sharecodefull.blogspot.com/2021/09/es-6-some-feature.html
0 comments :
About Me

- Peter
- Tân An, Long An, Vietnam
- Hello everyone, I love programming, I love making friends with people all over the world.
Contact
Popular Posts
-
The one of Design Pattern Series, this is factory design for createnal pattern. Please read in the linked document. Link document: https:...
-
youtube tutorial: https://www.youtube.com/watch?v=IEf1KAcK6A8 1 let and scope, 2 const, 3 array function 4 default value 5 Object iteral ext...
-
1 Copy Object in java Use = for immutable class ex: Integer , String or Wrapper classes Object Use Contructor has paramater copy, ObjectA...
-
JPA find() & getReference() in javax.persistence.EntityManager * find (): always call select from DB Use for select one entity from DB...
-
Preface Trong java có 3 kiểu so sánh đặc trưng như sau: + Sử dụng toán tử == : return Boolean Primitive thì so sánh giá trị thực, Reference ...
-
Persistence Context has two implemnet is JPA EntityManage and Hiberbate Session Example use Session of hiberate has exist github you can vi...
-
1 check Null and Undefined And primative datatype if(object){ // object is not null, undefined, 0, '', false. but it can empty({})...
-
1) CRUD có thể sử dung find Compositekey hoặc findBy compositeket + column in composite 2) CRUD findBy column And column 3 Not LazyLoa...
-
This post use language vietnames is, the future is will introduce english version. The clean code for java also application for the others. ...
-
Parse LocalDateTime to String to pattern year : yyyy || 2021 month of year: M / MMM / MMMM || 06 / Jun / June da...
Peter
Post a Comment