-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayAddOrRemove.js
More file actions
17 lines (17 loc) · 1.03 KB
/
arrayAddOrRemove.js
File metadata and controls
17 lines (17 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// add or remove from an array
const products = [
{ name: 'laptop', price: 3200, brand: 'len', color: 'silver' },
{ name: 'phone', price: 7000, brand: 'HTC', color: 'golden' },
{ name: 'watch', price: 3000, brand: 'casio', color: 'yellow' },
{ name: 'sungalss', price: 300, brand: 'ray', color: 'black' },
{ name: 'camera', price: 9000, brand: 'canon', color: 'gray' }
];
// array তে একটা অবজেক্ট এলিমেন্টকে যোগ করতে হলে ... সেই array তার সাথে newArray কে add করে দিতে হবে।
const newProduct = {name: 'webcam', price: 2000, brand: 'lal sing chadda', color: 'red'};
// add product
const addProduct = [...products, newProduct];
// console.log(addProduct);
// array এর এলিমেন্টের ডিলিট করতে চাইলে আমরা এই মেথড ব্যবহার করবো।
// remove product
const removeProduct = products.filter(p => p.name != 'laptop');
console.log(removeProduct);