1const newArr = [
2 {name: 'eve'},
3 {name: 'john'},
4 {name: 'jane'}
5].map(v => ({...v, isActive: true}))
1// given
2const obj = {
3 key1: value1,
4 key2: value2
5};
6
7// add pair
8obj["key3"] = value3;
9obj.key4 = value4;
1// original object { key1: "a", key2: "b"}
2var obj = {
3 key1: "a",
4 key2: "b"
5};
6
7// adding new filed - you can use 2 ways
8obj.key3 = "c"; // static
9// or
10obj["key3"] = "c"; // dynamic - 'key3' can be a variable
11console.log(obj) // {key1: "a", key2: "b", key3: "c" }
1var element = {}, cart = [];
2element.id = id;
3element.quantity = quantity;
4cart.push(element);
5
6// Array of Objects in form {element: {id: 10, quantity: 10} }
7var element = {}, cart = [];
8element.id = id;
9element.quantity = quantity;
10cart.push({element: element});