Array becomes an Integer after applying unshift on it

前端 未结 2 1402
借酒劲吻你
借酒劲吻你 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:16

    array.unshift() returns length of the modified array. It does not create a new array instead modifies the existing array. Thus you do not need to use any assignment here.

    var object ={
      "index": 0,
      "name": "b1a042ff6-0c75-4af2-a9da-1a16f333baee_p0",
      "category": "others",
      "rawUrl": "https://firebasestorage.googleapis.com/v0/b/vrcam-dev-5a815.appspot.com/o/5ab4f2a0-88e9-4bf5-86b5-61b528be707f/panoramas/panorama_XTsagLoxbA.png?alt=media&token=68ef261e-0c5e-4bf0-aebc-ab845fcec01a",
      "isTopLogo": false,
      "origin": "https://firebasestorage.googleapis.com/v0/b/vrcam-dev-5a815.appspot.com/o/5ab4f2a0-88e9-4bf5-86b5-61b528be707f/panoramas/panorama_XTsagLoxbA.png?alt=media&token=68ef261e-0c5e-4bf0-aebc-ab845fcec01a",
      "position": {
        "x": 0,
        "y": 0
      },
      "panoramaRotation": {
        "x": 0,
        "y": 0,
        "z": 0
      }
    }
    
    var array = [];
    
    array.unshift(object);
    
    console.log(array);

提交回复
热议问题