0

I am in process of reverse engineering a JS script. Somewhere is says:

var a = [{
    name: 'sample1',
     data: ["Otu1", "Otu2", "Otu3", "Otu4", "Otu5"],
     values: [5, 15, 250, 20, 23]
  },{
    name: 'sample2',
     data: ["Otu1", "Otu5", "Otu6", "Otu7"],
     values: [234, 29, 239, 5]
  }]

First question: What type of object is it? is it JSON? Or is it an array of JSON objects?

I need to write this in this form:

var b = {
    name: 'sample1',
     data: ["Otu1", "Otu2", "Otu3", "Otu4", "Otu5"],
     values: [5, 15, 250, 20, 23]
  }
var c = {
    name: 'sample2',
     data: ["Otu1", "Otu5", "Otu6", "Otu7"],
     values: [234, 29, 239, 5]
  }

var a = b + c 

Could you please help? Any insights are appreciated. Thank you community !

2 Answers 2

1

"First question: What type of object is it? is it JSON? Or is it an array of JSON objects?"

It's an Array of JavaScript Objects. It could be serialized into JSON data, but currently you should just see it as JavaScript code. The notation is similar, but the resulting data is different.

(And actually in your case, for the notation to be JSON-like, you'd need to use double quotes. But even then, you're still creating JavaScript Objects)

"I need to write this in this form: "

For this, you could make an Array of JavaScript Objects like this:

var a = [b, c];
Sign up to request clarification or add additional context in comments.

3 Comments

Thank u. will shortly try that out.
Thanks for the suggestion, but that didn't work. any other suggestion?
You need to give more information. What are you trying to do?
0

You have an array of Objects here, remember JSON simply means JavaScript Object Notation

Comments

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.