Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last month.
Improve this question
I have a following data, and I want to convert to list of array without key.
How do I do it?
Data
[{
"time": "01/13 15:50",
"price": 3000,
"changeRate": -0.27
},
{
"time": "01/13 15:40",
"price": 4000,
"changeRate": -0.27
}]
Desired output
[
[01/13 15:50, 3000],
[01/13 15:40, 4000]
]
Thank you in advance!
You can use the map method for that. It's used to transform (or "map") one array into a new one. The new array has the same length as the original, and its items are derived from the items in the original array.
data.map(item => [item.time, item.price]);
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
Hey Guys I am exporting some data.
And the challenge I am facing is the data should be in Array of Objects but don't know the data format is Array in Array of Objects.
I can write a script to transform the data to the desired format.
Can anyone help me out with how can I remove the object from the inner array to the outer array?
The data is in this format.
{
"data": [
[
{
"id": "4101"
}
]
]
}
My Resultant Format looks like this
Can anyone help me write a javascript to accomplish this objective
{
"data": [
{
"id": "4104",
}
]
}
Please give a try to this :
var a=obj.data.splice(0, 1);
obj.data.push(a[0]);
or in one line if you want :
obj.data.push(obj.data.splice(0, 1)[0]);
Provided you cannot correct the input at the source.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
first of all, I really haven't learn any javascript at all, and I am stuck here.
I want to get these link in this JSON example.
"list": [
[
"List of recipes",
[
{
"name": "Eggs",
"links": [
{
"method": "Fry",
"link": "https://example.com/category/fry"
},
]
},
]
]
I can't elaborate with my friend's example code, can anyone help me?
Your JSON isn't valid so you need to fix that first.
When it's valid parse it with JSON.parse.
When it's parsed you'll have a nested array data structure. You need to access the links array by navigating through the tree with the array indexes.
// Returns an array
data.list[0]
// Get the second element of that array
// (the first element is the text "List of recipes")
// which is also an array
data.list[0][1]
// Access the first element of that array
// (an object) and return the links array
data.list[0][1][0].links
const json = '{"list":[["List of recipes",[{"name":"Eggs","links":[{"method":"Fry","link":"https://example.com/category/fry"}]}]]]}';
const data = JSON.parse(json);
console.log(data.list[0][1][0].links);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have two JSON objects and I'm planning to join them.
obj1 = [{'foo': 'bar', 'foo1': 'bar1'}];
obj2 = [{'foo2': 'bar2'}];
objFinal = [
{
"foo": "bar",
"foo1": "bar1",
"title":
[
{ "foo2": "bar2" }
]
}
]
My plan is to get the result the same as objFinal. I've used .concat but it didn't returned the result I wanted. What are other options I can do to get the result as same as objFinal?
Please use this code.
objFinal = [{ ...obj1[0], title: obj2}];
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm trying to add a new item (a placeholder) to an array -- to each node
My array looks as follow:
And I wanna add the following key/value under value Year: "2010"
I have tried *json1.push("Year", "2010")* but that just creates a new entry
If you want to add it to the first object on the array, use
json1[0]["year"] = "2010"
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I want to push an item into an array that in that have objects in them, like this:
var testarray = [
{
first: "See this?",
second: "Oh my!"
},
{
first: "Nice!",
second: "Amazing!"
}
]
You can see that I for this variable/array, I can't just use this testarray.push("Wonderful!"). Please show me how I can push things into these sort of arrays.
The "multiple things" are objects. Push another object in the same format.
testarray.push({first: "Wow!", second: "Wonderful!"});