Tag: arrays

checking if javascript array contains value using underscorejs

I have an array of cars like this: [{ name:”Toyota Minivan”, id:”506″ }, { name:”Honda Civic”, id:”619″ }] I am trying to check whether the array contains a certain id. I have tried var x =!!_.where(cars, {id:’506′}).length; expecting it to return true if the array contains the id, but it always returns false. What am […]

How can I determine if an element is contained in an Array without looping?

How can I check whether a particular element is inside an array? I don’t want to manually write a loop for this; instead I want to use a JavaScript built-in function, maybe something equivalent to new Array(0,1,2,3,6,9,12,15,18).Contains(5) //return false new Array(0,1,2,3,6,9,12,15,18).Contains(1) //return true

Inserting PHP array into Javascript array

I have an array like this: Array ( [0] => Array ( [id] => 9826 [tag] => “php” ) [1] => Array ( [id] => 9680 [tag] => “perl” ) ) I want to pass this to a javascript variable that looks like this: var availableTags = [ “ActionScript”, “AppleScript”, “Asp”, “BASIC”, “C”, “C++”, “Clojure”, […]

Replacing values in JSON object

I have the following JSON object data returned from my apicontroller : > [ {“id”:2,”text”:”PROGRAMME”,”parent”:null}, > {“id”:3,”text”:”STAGE”,”parent”:2}, > {“id”:4,”text”:”INFRA”,”parent”:2}, > {“id”:5,”text”:”SYSTEM”,”parent”:3}, > {“id”:6,”text”:”STOCK”,”parent”:3}, {“id”:7,”text”:”DPT”,”parent”:3}, > {“id”:9,”text”:”EXTERNAL”,”parent”:null} ] I want to replace “parent”:null with “parent”:'”#”‘ I have tried the code below, but it is only replacing the first occurrence of “parent”:null. How can I replace all […]

How to use array reduce with condition in JavaScript?

So I have an array const records = [ { value: 24, gender: “BOYS” }, { value: 42, gender: “BOYS” }, { value: 85, gender: “GIRLS” }, { value: 12, gender: “GIRLS” }, { value: 10, gender: “BOYS” } ] And I want to get the sum so I used the JavaScript array reduce function […]

JavaScript literal, pointer value for key

I have the following code: name= “a”; value=”b” $.post(“ajax.php”, {name:value})…. However ajax.php will receive name=b instead of a=b. How would I make it receive the latter?

Javascript 4D arrays

Anyone have a function to create 4D arrays (or any number of dimensions for that matter)? I’d like to call the function, then after that I can do something like arr[3][2][23][12] = “awesome”;

What type of data is this JavaScript code?

Well, I’m completely new to JavaScript. Can you please tell me what type of data is this JavaScript code: var options = { sourceLanguage: ‘en’, destinationLanguage: [‘hi’, ‘bn’, ‘fa’, ‘gu’, ‘kn’, ‘ml’, ‘mr’, ‘ne’, ‘pa’, ‘ta’,’te’,’ur’], shortcutKey: ‘ctrl+g’, transliterationEnabled: true }; I’ve reviewed JavaScript arrays, but it doesn’t seem to be a traditional array. Still […]

Convert array of string javascript to array of integer javascript

I have an array, var array = [“1″,”2″,”3″,”4″,”5”]; then I need to convert to var array = [1,2,3,4,5]; How can i convert?

Javascript (dynamic) insert into array, then shift all elements underneath +1

Didn’t really found a solution to this for Javascript. What I need; I want to insert an element into an array, but not really overwrite that element. Rather a ‘dynamic’ insert. Thus Insert element, then shift all elements underneath it by +1 index. For instance: I have an array “14S” “16S” “19S”. I know want […]