Add an attribute and default value to each element in the array

Add an attribute and default value to each element in the array

Below is the code

        var articlelist = []
        articleArr.map(((item, index) => {
          articlelist.push(Object.assign({}, item, {
            state: false,
            opened: '+'
          }))
        }))

Result: All the elements in the articleArr array are copied to the articlelist array, and the state attribute with a value of false and the opened attribute with a value of '+' are added.

Published an original article · Likes0 · Visits1

Guess you like

Origin blog.csdn.net/vbdak2000/article/details/105464844