1const items = [
2 { id: 1, name: 'Nike Air Max 97', inStock: true },
3 { id: 2, name: 'Adidas Continental', inStock: true },
4 { id: 3, name: 'Adidas Supercourt', inStock: true },
5 { id: 4, name: 'Nike Jordan Dunks', inStock: true }
6]
7// ? Create a new array "itemsCopy" from it using map
8// update the Nike Jordans Dunks in the copyArray to
9// have an "inStock" value of false.
10// Make sure using console.log that you have not affected
11// the original items array.
12const itemsCopy = items.map(item => {
13 if (item.id === 4) {
14 return { ...item, inStock: false }
15 }
16 return { ...item }
17})
18console.log('og', items)
19console.log('new', itemsCopy)
1//access value by using map
2var personsInfo = {
3 company: 'sp-coder',
4 persons: [{
5 id: 1,
6 name: 'Adil'
7 }, {
8 id: 2,
9 name: 'Arif'
10 }]
11};
12const getNames = personsInfo.persons.map((data) => data.name);
13console.log(getNames);
14//Expected Output is [ 'Adil', 'Arif' ]