Skip to content

Tag: arrays

How to convert array into JavaScript object

I have an array like this (which is similar to a JSON array) of length n: I would like to convert it into a nested Object like so: Essentially, the object is categorised according to the categorynumber and then optionnumber. (Please keep the format of “Phrase 4” and “Phrase 5” in view.…

build array of json object while looping array of data

I have an array const A=[‘string1′,’string2′,’string3’]. I want to achieve an object that has the following form: This is what I’ve tried: But the result is an array filled with undefined values. Answer I do not understand why are you using JSON.stringify()? The simpl…