php - giving a different value to a variable on each different value from a JavaScript array -


i have js array more million entries.

i want javascript assign specific color flag on every different value array

say array contains this:

var foo = new array([10,20,30,40,50,36,60,70,80,90,100]); 

it worth knowing array contains 58 different values.

i trying this:

if (foo.every(10)) flag = "red"; if (foo.every(20)) flag =  "yellow"; 

i need way values in array without having repeat line above 58 times.

note know flag overridden , flag in code unique every different value.

also note array imported json data mysql table using php, php approaches problem appreciated.

easy js solution:

var numbertocolordictionary = {     10: "red",     20: "yellow"     ... }  // after runs, 'flags' should contain right flags.  var flags = foo.map(function(number) {     return numbertocolordictionary[number]; }); 

although, sound you're querying database wrong. if numbers ids mysql, should use join correct flags.

and way, don't need new array syntax. do:

var foo = [10,20,30,40,50,36,60,70,80,90,100]; 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -