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 5 years ago.
Improve this question
I have tried everything I can think of to get the data but cannot figure this out.
The data is in a structure like this:
[{"code":1000,"day":"Sunny","night":"Clear","icon":113,"languages":
[{"lang_name":"Arabic","lang_iso":"ar","day_text":"مشمس","night_text":"صافي"}]
}]
I've tried looping, using key:value using the dot notation and bracket notation and cannot get the info.
I'm trying to get to the "languages" so I can parse them for the weather.
var arr = [{"code":1000,"day":"Sunny","night":"Clear","icon":113,"languages":
[{"lang_name":"Arabic","lang_iso":"ar","day_text":"مشمس","night_text":"صافي"}]
}]
arr.forEach(function(obj){ //loop array
obj.languages.forEach(function(language) { //loop languages
console.log(language); //language object
console.log(language.lang_name); //language property
});
});
Related
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
With the following array of strings in javascript, is there a way to use the .filter to filter by the first word?
['Desk_One', 'Desk_Two', 'Desk_Three', 'Chair_One', 'Chair_Two']
For example to .filter(x = 'Desk_*')
['Desk_One', 'Desk_Two', 'Desk_Three']
Maybe this needs to be a regex
You can use startsWith() function like this:
let array = ['Desk_One', 'Desk_Two', 'Desk_Three', 'Chair_One', 'Chair_Two'];
let result = array.filter((item)=>item.startsWith(array[0].split('_')[0]));
console.log(result)
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
So I’m trying to check names through an array and I don’t want to have to use
if (<array name>[0,1,2,3,4,5,6,7])
{ code in here }
depend on what you are trying to do u can use forEach or map
let arr = [1,2,3,4,5,6,7,8,9,10];
arr.forEach((item)=>{
console.log(`${item} is greater than 5 : ${item>5}`)
})
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 7 years ago.
Improve this question
Below is my JSON object
{"Decision":[{"recid":"1183","reason":"Approved as Requested","decision":"Approved","approvalamt":"","comment":""},{"recid":"662","reason":"3","decision":"Rejected","approvalamt":"","comment":""},{"recid":"752","reason":"Approved People Resources; But No Funding Approved","decision":"Approved","approvalamt":"","comment":""}]}
How do I get length of this.In this example it should return me 3.
My Object name is DecisionObj which have above listed elements.
var string = '{"Decision":[{"recid":"1183","reason":"Approved as Requested","decision":"Approved","approvalamt":"","comment":""},{"recid":"662","reason":"3","decision":"Rejected","approvalamt":"","comment":""},{"recid":"752","reason":"Approved People Resources; But No Funding Approved","decision":"Approved","approvalamt":"","comment":""}]}';
var object = JSON.parse(string);
alert(object.Decision.length);
Arrays have length property. You can use that.
var length = DecisionObj.length;
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 8 years ago.
Improve this question
I want to have an array containing an object. For example I have an object like this:
parentObj:{
childObj1,
childObj2
}
but I want to have a "parentObj" array and be able to call it like :
parentObj[0].childObj1
I searched a lot but didn't find anything related to this. I'll appreciate if someone can help me with this.
thanks very much
Here's an array of objects:
var a = [
{name: "first"},
{name: "second"}
];
console.log(a[0].name); // "first"
console.log(a[1].name); // "second"
The [] is an array initializer. The {} is an object initializer.
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 9 years ago.
Improve this question
I was looking for some way to make calculations on values inside array. I know that I can sum the values, sort it or returs max/min. But I am novice and i do not find anything about harder math. I have formula:
http://i.imgur.com/O5tNmMh.jpg
(can't attach images yet...)
And I have an array [somex, somey, somex, somey,somex, somey, ....] Is it possible to calculate the thing like that?
you need some logic like this:
int current=0 ,previous=0,yoursum=0;
for(i=0;i<no. of elements in array;i++)
{
current=arr[i];
else
{
yoursum+=previous-current;
previous=current;
}
}