亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

node.js - How to get loop variables in nodejs using for of to traverse Map
phpcn_u1582
phpcn_u1582 2017-06-14 10:52:45
0
2
1738

My problem is to prevent duplicate data from being inserted when adding data to the array, so I thought of map, but I don’t know how to get the index after traversing the Map structure. If I don't use map, is there any other concise way?

phpcn_u1582
phpcn_u1582

reply all(2)
滿天的星座

`for(value of map){

console.log(value[0]);

}`

學(xué)習(xí)ing

1. The simplest

Every time you insert it, use the unique key to check whether it already exists

2. Use Object method when storing

let data = {
    [id]: {
        ...obj,
        index: Number // 代表原來的索引
    }
}

If you want to sort things in order when calling, use index to sort and then output.

Object.values(data).sort((a, b) => a.index - b.index);

3. Create an index table while saving Array

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template