0

I am working with an array that is formatted like this

[
[{
    "ID": "f75d414d-55fc-43c8-a24d-34eca67913b7",
    "Revision": "a8c73a24-d46a-47c8-825e-511b26485e23",
    "type": "Hello",
    "Stage": null,
    "label": null,
},
{
    "ID": "f75d414d-55fc-43c8-a24d-34eca67913b7",
    "Revision": "a8c73a24-d46a-47c8-825e-511b26485e23",
    "type": "world",
    "Stage": null,
    "label": null,
}]
]

That I need converted to this

[{
    "ID": "f75d414d-55fc-43c8-a24d-34eca67913b7",
    "Revision": "a8c73a24-d46a-47c8-825e-511b26485e23",
    "type": "Hello",
    "Stage": null,
    "label": null,
},
{
    "ID": "f75d414d-55fc-43c8-a24d-34eca67913b7",
    "Revision": "a8c73a24-d46a-47c8-825e-511b26485e23",
    "type": "world",
    "Stage": null,
    "label": null,
}]

by saving a variable (the original array) to itself some way. A slick way would be nice.

skwidgets
  • 281
  • 2
  • 8
  • 23
  • 1
    Just do `arrayName = arrayName[0]` – tewathia Feb 20 '14 at 03:46
  • 2
    You are basically asking how to access the first element of an array. This should be [covered by any JavaScript tutorial](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Predefined_Core_Objects#Referring_to_Array_Elements). – Felix Kling Feb 20 '14 at 03:47
  • `var a = [[{ID:...},{ID:...}]][0];` – RobG Feb 20 '14 at 03:48
  • Is it actually a **JS Array**, or is it **JSON** text? If it's JSON, then the obvious thing to do would be to parse it, though with such a minor change, you could really do it with string manipulation too, like `data.trim().slice(1,-1)`. But if you're ultimately going to parse it anyway, you might as well just go ahead and do that. – cookie monster Feb 20 '14 at 03:54

1 Answers1

1

Off the top of my head wouldn't originalArray = originalArray[0] save the inner array back to the original variable?

MikeHe
  • 68
  • 6