-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtoolbox.js
More file actions
59 lines (47 loc) Β· 1.28 KB
/
toolbox.js
File metadata and controls
59 lines (47 loc) Β· 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const rojArray = {
addObjectToArray: (arr, obj) => {
arr.push(obj);
},
removeObjectById: (arr, id) => {
const index = arr.findIndex(item => item.id === id);
if (index !== -1) {
arr.splice(index, 1);
}
},
updateObjectById: (arr, id, newData) => {
const index = arr.findIndex(item => item.id === id);
if (index !== -1) {
arr[index] = {
...arr[index],
...newData
};
}
},
displayArray: arr => {
arr.forEach(item => {
console.log(item);
});
},
removeObjectByField: (arr, field, value) => {
const index = arr.findIndex(item => item[field] === value);
if (index !== -1) {
arr.splice(index, 1);
}
},
updateObjectByField: (arr, field, value, newData) => {
const index = arr.findIndex(item => item[field] === value);
if (index !== -1) {
arr[index] = {
...arr[index],
...newData
};
}
},
searchObjectsByField: (arr, field, value) => {
return arr.filter(item => item[field] === value);
},
displayObjectsInRange: (arr, start, end) => {
const filteredObjects = arr.filter(item => item.id >= start && item.id <= end);
return filteredObjects;
},
};