0

This is my output

[{"Phy_nm":"HCP-1","Brand_t":126.52,"Mkt_volume":181.23,"calls_recvd":7.94,"samples":30.86,"Avg":24.14}]

I tried doing this

var i = 0, result = [];

    while (i < data.length) {
        result.push([])
        for (var key in data[i].fields) {
            result[result.length - 1].push(data[i].fields[key])
        }
        i++
    }

How can I convert this to array of array in javascript like this

[
[{"Phy_nm":"HCP-1","Brand_t":126.52,"Mkt_volume":181.23,"calls_recvd":7.94,"samples":30.86,"Avg":24.14}]
]
6
  • so you want to add your json to an array Commented Nov 5, 2017 at 18:05
  • 1
    var data = [{"Phy_nm":"HCP-1","Brand_t":126.52,"Mkt_volume":181.23,"calls_recvd":7.94,"samples":30.86,"Avg":24.14}]; var result = [data];. This should do. Commented Nov 5, 2017 at 18:05
  • please add what is given and what you want to get. Commented Nov 5, 2017 at 18:06
  • Yeah I agree with @HassanImam and if you think you have a list of data then just do like this oldData.map(d){ result.push([d])} Commented Nov 5, 2017 at 18:13
  • Is it similar to this one: (create an array of arrays) stackoverflow.com/questions/16192925/… Commented Nov 5, 2017 at 18:14

2 Answers 2

0

I dont get the logic tho...

since you are sure that your output will always be a valid JSON

var Output =[{"Phy_nm":"HCP-1","Brand_t":126.52,"Mkt_volume":181.23,"calls_recvd":7.94,"samples":30.86,"Avg":24.14}]

so the desired output would be this simple string trick

   var result = "[" + JSON.stringify(Output)  + "]";
Sign up to request clarification or add additional context in comments.

1 Comment

No this will not create array of array, I trying to to do something like this Array[Array(1)]
0

You want to insert that Json to an array,in this case we simply do this.

var dataOutput =[{"Phy_nm":"HCP-1","Brand_t":126.52,"Mkt_volume":181.23,"calls_recvd":7.94,"samples":30.86,"Avg":24.14}]
var output=[dataOutput];

1 Comment

Yes this what I was expecting.., as Hassan Imam said!! Thanks for your help!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.