Array becomes an Integer after applying unshift on it

前端 未结 2 1404
借酒劲吻你
借酒劲吻你 2021-01-23 02:47

I have an Object like this:

{
  \"index\": 0,
  \"name\": \"b1a042ff6-0c75-4af2-a9da-1a16f333baee_p0\",
  \"category\": \"others\",
  \"rawUrl\": \"https://fireb         


        
2条回答
  •  逝去的感伤
    2021-01-23 03:09

    The docs explain

    The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.

    Maybe instead of assigning the result of unshift, do

    const newClonedArray = JSON.parse(JSON.stringify(array));
    newClonedArray.unshift(object);
    

提交回复
热议问题