Reputation: 28783
I have a variable like so:
columnData = new Array(columnWidth, columnIndex);
both values are numbers
and then I want to do the following:
thiscolumnWidth = columnData[1] WHERE columnData[2] == cellIndex;
the idea is that I want the thiscolumnWidth
to be the value of the first value in the array of columnData
where the second value columnData
matches the cellIndex
value.
The reason for doing it this way is because all of this sits inside a foreach loop so therefore it needs to find the correct array in memory! This ALL WORKS apart from the Where clause which doesn't exist in JS.
Can anyone help? Cheers
Upvotes: 2
Views: 2582
Reputation: 2923
Give this a whirl, developed in WSH, but will work anywhere JavaScript runs.
var aValues = new Array();
aValues[100] = 123;
aValues[200] = 234;
aValues[300] = 234;
var nValue = aValues[100];
WScript.Echo( nValue );
var nValue = aValues[200];
WScript.Echo( nValue );
Upvotes: 1
Reputation: 30872
Aside from using JSLINQ you could simply do something like:
if (columnData[2] == cellIndex){
thiscolumnWidth = columnData[1];
}
Upvotes: 2