Sunday, October 31, 2021

Assign object in another object in javascript

 let person = {

  fanme: "Jitendra",

  lname: "Singh",

};


let person1 = person;

person2.lname = "pal";

// It will change the original object (person1)


let person2 = Object.assign({}, person);

person2.lname = "mishra";

// It will not change the original object


let person3 = Object.create(person);

person3.lname = "yadav";

// It will not change the original object


let person4 = {...person};

person4.lname = "pandey";

// It will not change the original object


console.log(person);

console.log(person2)

console.log(person3);

console.log(person4);


https://jsfiddle.net/jitsingh79/cvqz1j3h/31/



Find the value from array when age is more than 30

 const data = [   { id: 1, name: 'Alice', age: 25 },   { id: 2, name: 'Bob', age: 30 },   { id: 3, name: 'Charlie', ...