All Questions

Tagged with
Filter by
Sorted by
Tagged with
2122 votes
26 answers
1.3m views

How do I check if a variable is an array in JavaScript?

How do I check if a variable is an array in JavaScript? if (variable.constructor == Array)
Andy McCluggage's user avatar
414 votes
15 answers
580k views

Determine if string is in list in JavaScript

In SQL we can see if a string is in a list like so: Column IN ('a', 'b', 'c') What's a good way to do this in JavaScript? It's so clunky to do this: if (expression1 || expression2 || str === 'a' || ...
ErikE's user avatar
  • 49.6k
337 votes
5 answers
247k views

Is the order of elements in a JSON list preserved?

I've noticed the order of elements in a JSON object not being the original order. What about the elements of JSON lists? Is their order maintained?
user437899's user avatar
  • 9,029
225 votes
34 answers
280k views

Build tree array from flat array in javascript

I have a complex json file that I have to handle with javascript to make it hierarchical, in order to later build a tree. Every entry of the json has : id : a unique id, parentId : the id of the ...
Franck's user avatar
  • 2,489
127 votes
5 answers
370k views

how to add new <li> to <ul> onclick with javascript

How do I add a list element to an existing ul using a function from an onclick? I need it to add to this type of list ... <ul id="list"> <li id="element1">One</li>...
Uni's user avatar
  • 1,431
111 votes
11 answers
102k views

Big list performance with React

I am in the process of implementing a filterable list with React. The structure of the list is as shown in the image below. PREMISE Here's a description of how it is supposed to work: The state ...
Dimitris Karagiannis's user avatar
72 votes
9 answers
43k views

Javascript equivalent of PHP's list()

Really like that function. $matches = array('12', 'watt'); list($value, $unit) = $matches; Is there a Javascript equivalent of that?
Markus Hedlund's user avatar
71 votes
3 answers
54k views

JavaScript filter that stops at the first result

Is there a mechanism in JavaScript (without having to write my own) similar to filter. Instead of returning all the filtered elements of a collection though, it only returns the first one. Of course I ...
at.'s user avatar
  • 51.8k
41 votes
3 answers
16k views

What is the equivalent of Python any() and all() functions in JavaScript?

Python has built in functions any() and all(), which are applied on a list (array in JavaScript) as following- any(): Return True if any element of the iterable is true. If the iterable is empty, ...
Workonphp's user avatar
  • 1,655
37 votes
3 answers
26k views

How to get union of several immutable.js Lists

So, I have List a: let a = Immutable.List([1]) and List b: let b = Immutable.List([2, 3]) I want to get List union === List([1, 2, 3]) from them. I try to merge them fist: let union = a.merge(b)...
Boris Zagoruiko's user avatar
34 votes
5 answers
23k views

Dealing with an empty list in mustache.js

I'm using mustache.js to render a template in javascript. I'd like to check if a list is empty or not to hide the <h2> tag in the following example. Is this possible or is mustache.js too logic-...
Max Schmidt's user avatar
  • 7,505
34 votes
5 answers
54k views

How do I remove an element in a list, using forEach?

var people = ['alex','jason','matt']; people.forEach(function(p){ if(p.length > 4){ //REMOVE THIS PERSON or pop it out of the list or whatever } }); console.log(people) //should ...
TIMEX's user avatar
  • 265k
31 votes
2 answers
79k views

how to add spaces between array items javascript

I am a beginner at javascript so I appreciate any help/advice given. My issue here is that I'm trying to figure out how to add space between items in the times[] array which holds the values for ...
user1876829's user avatar
29 votes
5 answers
43k views

What is the highest performance way to filter a list of JSON objects in JavaScript?

Let's assume I have a huge (1000+) list of objects like this: [{name: 'john dow', age: 38, gender:'m'}, {name: 'jane dow', age: 18, gender:'f'}, ..] I want to filter this list by name (character ...
wzr1337's user avatar
  • 3,709
29 votes
5 answers
110k views

A list of tuples in Javascript [closed]

Let's say I receive a JSON-string containing information about people. Now I loop through all the JSON-objects and extract the name and age or each person. How would I store these as tuples in a list ...
Boris's user avatar
  • 8,753
26 votes
8 answers
78k views

Sorting dropdown list using Javascript

i want to sort the drop down items using javascript,can anyone tell me how to do this.
Chetan's user avatar
  • 1,557
24 votes
7 answers
51k views

Partitioning in JavaScript [duplicate]

Please consider an array such as : arrayAll = [1,2,3,4,5,6,7,8,9] Is there a package that enable to do partitioning to obtain : arrayALLPartionned = [[1,2,3],[4,5,6],[7,8,9]] I can see how to do ...
500's user avatar
  • 6,569
22 votes
7 answers
41k views

material ui: how to change fontSize in Lists?

I am creating some forms using react js and material UI. I would like to make the font size on some of the lists smaller in order to get a more compact presentation, but no matter at which level I ...
levraininjaneer's user avatar
19 votes
7 answers
54k views

How to scroll to li element in a ul list

I have a ul list inside a div with li elements and inside the li elements is a single checkbox. I have the id for the checkboxes. So I want to get the parent li element of the checkbox and scroll to ...
kyleb's user avatar
  • 2,020
17 votes
9 answers
39k views

How to loop through the alphabet via underscoreJS

I'm using Underscore's template() method in BackboneJS views. I'd like to show a list of alphabet letters in my view in order to sort a collection by letter. As a result, I have a list of 26 links (...
JeremyW's user avatar
  • 713
15 votes
2 answers
10k views

Prevent Selectize automatic sorting

I have an array of objects that is provided from a WebService (the order of the list is important). I loaded the JSON object into a Selectize control but it re-orders the list without using the order ...
eliashdezr's user avatar
  • 2,105
14 votes
4 answers
23k views

Display JSON data on a page as a expandable/collapsible list

I need help with with displaying JSON data on a page like expandable/collapsible list. Here is a valid JSON I`ve made converting from XML with Python: JSON Data And to display it I`m usig this: &...
MilicaJ's user avatar
  • 141
14 votes
1 answer
49k views

Jquery before submitting the form

I have a list, (a simple list) from which i am able to select and set elements (using js), and then a form that allows me to choose how many elements i want, and a submit form.if one doesn't select an ...
dana's user avatar
  • 5,248
13 votes
1 answer
24k views

How to list contents of a directory IN ORDER with node.js?

I'm a fairly experienced programmer and I've just recently discovered node.js. I love JavaScript because that's where I started (Web Development) so being able to write server-side code with its is ...
Brandon's user avatar
  • 4,493
13 votes
1 answer
5k views

react-window set item size according to content height

I'm using react-window to implement a chat message list, but I'm getting stuck trying to set the right itemSize to each item. Happens that a chat message, based on his text length and window width, ...
Marco Nobile's user avatar
12 votes
4 answers
30k views

AngularJS ng-disabled not working with list items

I am facing a problem with disabling a item in the list. <div id="searchdropdown"> <ul> <li>list1</li> <li ng-disabled="someCondition" ng-click="...
Hmahwish's user avatar
  • 2,232
12 votes
1 answer
40k views

Sort a list by id by using javascript [duplicate]

I'm making a phonegap app on iOS that requires sort a list by time I tried add the time to the id of each li item and then sort based on the id <ul id="test"> <li id="4112">blub</li&...
ThangPQ's user avatar
  • 121
11 votes
1 answer
18k views

Javascript sorted lists

Is there a sorted list in Javascript or jQuery? I have a huge list with few insert actions over time. I cannot afford to call object.sort() for the entire list each time I add a single item. I need ...
eshalev's user avatar
  • 3,083
10 votes
3 answers
94k views

Push values to array in jquery

I have List of items data and empty array quotations : var data = {}; var quotations = []; I want to fill quotations with data values ,Every time i add new data it added successfully but all ...
prime's user avatar
  • 351
10 votes
4 answers
378 views

Best way to store a huge list with hashes in Javascript

I have a list with 10.000 entrys. for example myList = {}; myList[hashjh5j4h5j4h5j4] myList[hashs54s5d4s5d4sd] myList[hash5as465d45ad4d] .... I dont use an array (0,1,2,3) because i can check very ...
Peter's user avatar
  • 11.7k
9 votes
4 answers
20k views

Is there any method/way in javascript to add a child node to list element dynamically?

If I have an unordered list like <ul id="list"> <li>Helo World-1</li> <li>Helo World-2</li> <li>Helo World-3</li> </ul> I want to add a sublist item ...
XCeptable's user avatar
  • 1,247
9 votes
5 answers
28k views

Search for an item in a list using jquery .filter()

I'm trying to input an input that looks into my list and returns the result below. This is my list <ul id="lista1" class="list-group"> <li id = "1" class="list-group-item d-flex ...
user avatar
9 votes
3 answers
40k views

Trigger event when selecting in a dropdown javascript eventlistener

I have this javascript function, function listQ(){ var e = document.getElementById("list"); if(e.selectedIndex > 0){ if("Blank Test" === e.selectedIndex){ alert("yo"); } } } My problem is ...
John Arellano's user avatar
9 votes
5 answers
9k views

is there some method of array like set in python?

As I know in python i can set a list to a unique list like: In [12]: a=range(12) In [13]: a.append(5) In [14]: a.append(4) In [15]: a.append(5) In [16]: a Out[16]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...
timger's user avatar
  • 952
8 votes
6 answers
10k views

JavaScript Collections API?

I've searched quite a while for a Collections API (list, set) for JS and surprisingly I could only this: http://www.coffeeblack.org/work/jscollections/ This is exactly what I was looking for, but I'm ...
simpatico's user avatar
  • 10.9k
8 votes
2 answers
12k views

Django Dynamic Drop-down List from Database

I wanted to develop a Django app and one of the functionalities I'd like to have is dynamic drop-down lists...specifically for vehicle makes and models...selecting a specific make will update the ...
user avatar
7 votes
7 answers
30k views

how to remove all li in my ul through with it id?

I have a ul list. I want to remove all li in my ul through with it id?
w3father's user avatar
  • 569
7 votes
8 answers
34k views

Convert Java List to Javascript Array

I have the following java code in my Android application and wanted a way to convert the Java list to an array that can be used in javascript: Java: public void onCompleted(List<GraphUser> ...
Prabhu's user avatar
  • 13.2k
7 votes
1 answer
13k views

Filtering Nested Array with Lodash/Javascript

I have the following object array: var sizeList = [ { id: 1, title:"Test1", type:[{name:"Big", present:false}, {name:"Small", present:true}, {name:"Medium", present:false}] }, { ...
lost9123193's user avatar
  • 10.8k
7 votes
4 answers
53k views

How to get elements inside tags using queryselector?

var divElement = document.createElement("div"); divElement.setAttribute('id', 'Items'); var ulElement = document.createElement("ul"); var liElement = document.createElement("li"); var spanElement1 = ...
coder's user avatar
  • 159
7 votes
1 answer
1k views

Possible to get list item (<li>) label with JavaScript?

If I've got a ul with 3 items in it and the list-style-type is set to lower-alpha, I end up with this a. Item 1 b. Item 2 c. Item 3 With jQuery, I can easily get the value of any item ...
matthew Rhodes's user avatar
7 votes
3 answers
2k views

Array comprehension in JavaScript? [duplicate]

I was wondering what the neatest way would be to convert (from Python) a list comprehension into Javascript. Is there anything which will make this readable and not a mess? non_zero_in_square = [ ...
Andy Hayden's user avatar
7 votes
2 answers
3k views

Error in building Sencha Touch 2 application

While I am building my sencha touch 2 app using the command:- sencha app build production but it throws an error: [INFO] Deploying your application to /Applications/MAMP/htdocs/iPadapp/build/...
heyjii's user avatar
  • 834
7 votes
4 answers
13k views

Filling a dropdown list based on another dropdown list in the same html form

I have an HTML form with a bunch of options inside and I'd like to change the values inside those options based on previous user selection: Let's say I have something like this: <select name="...
TheNoobUser's user avatar
6 votes
3 answers
60k views

AngularJS display list from an array

I have a controller that returns an array, I'm trying to display every element of that array as a list. What I am attempting to do, which is not working: <li ng-repeat="Name in names"> <...
Abushawish's user avatar
  • 1,475
6 votes
3 answers
16k views

Using createTextNode() but I need to add HTML tags to it (JavaScript/JQuery)

When I click an item in a table, I need it to add that item to a list and display that list. Here's my code for adding/displaying the items in the list: var myList = document.getElementById('my-...
Nathan R's user avatar
  • 860
6 votes
5 answers
17k views

An automatically scrolling live ticker (like the "Top Tweets" of Twitter)

Is there a good Javascript library for generating an automatically scrolling list like the "Top Tweets" on the Twitter homepage? Preferable as jQuery plugin. It should also support AJAX functionality (...
medihack's user avatar
  • 16.3k
6 votes
2 answers
17k views

Google Maps API: pan to markers from a list.

Hello :) Please bear with me, I'm not a coder but I'm trying to learn by doing. This is the page I'm working on currently; http://www.websu.it/devnw/dev/contact.html. I've currently set up a map using ...
Robin Papa's user avatar
6 votes
2 answers
5k views

How to toggle class for the only one element on click in react

I am trying to make a flipped set of cards in React. You can see my code below. When I click on the card, they all flipped, but my goal is to flip only those that i clicked on. How can I do this? ...
Lev Vysokiy's user avatar
6 votes
1 answer
2k views

regex to replace 0 in list but not 0 of 10, 20, 30, etc. - using js replace

I'm trying to create a regex to replace zeros in list with an empty value but not replace the zeros in ten, twenty, thirty, etc. list = 0,1,0,20,0,0,1,,1,3,10,30,0 desired list = ,1,,20,,,1,,1,3,10,...
shaunw's user avatar
  • 364

1
2 3 4 5
40