1. The obtained json data is like this
data:[
{
'Id': '1',
'Phone': '123456',
'Name': '张三',
},
{
'Id': '2',
'Phone': '78945',
'Name': '李四',
},
{
'Id': '3',
'Phone': '123789',
'Name': '王五',
}
]
Take out the Name of each object in the array to generate a new array
let results = data.map(data => n.name);//['张三','李四','王五']
Check if a value exists in an array
let results = data.filter(item => item.Name==='王五' );
Remove empty array empty string, undefined, null
var arr = ['1','2',undefined, '3.jpg',undefined]
var newArr = arr.filter(item => item)
filter non-compliance
var arr = ['10','12','23','44','42']
var newArr = arr.filter(item => item.indexOf('2')<0)
Array deduplication
方法1:
var arr = [1, 2, 2, 3, 4, 5, 5, 6, 7, 7,8,8,0,8,6,3,4,56,2];
var arr2 = arr.filter((x, index,self)=>self.indexOf(x)===index)
方法2:
var arr = [1,2,3,4,3,4];
var arr2 = [...new Set(arr)];
swap the values of two variables
let [x,y] = [1,2];
[y,x] = [x,y];
convert array to object
var data=[1,2,3,4]
var data1 ={...data}
Filter two array objects for different values
let arr1=[{id:1,name:'网'},{id:2,name:'二位'}]
let arr2=[{id:1,name:'问问'},{id:3,name:'多少'},{id:44,name:'多少'},{id:45,name:'多少'},]
let result = arr2.filter((item) => !arr1.some((ele) => ele.id=== item.id));
//result = [{id:3,name:'多少'},{id:44,name:'多少'},{id:45,name:'多少'}]
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。