I’m new to javascript and have a simple task. I have an array “values” and a second array “gender”, and I want to create a third array which is “values” where gender == “Males”. The variables look like this:
var values = new Array();
values[0] = .1
values[1] = .3
values [2] = .7
values[3] = .8
var gender = new Array();
gender[0]='Males'
gender[1]='Males'
gender[2]='Females'
gender[3]='Females'
The equivalent syntax in python would be:
female_values = values[gender=='Females']
Any thoughts?
The
Arrayconstructor is not usually used, use the array literal[]instead. Then simply loop through the arrays and push the value onto the third array if some condition that you set passes.And yeah this is more pain than python, although coffee script can make it a little nicer.