JavaScript select specific numbers out of array select specific numbers in excel,select specific numbers,select specific

this might be a very basic question. But I would like to know how I can select specific elements out of an array. I have an array with 100 elements:

var cubes = [element1, element2, element3 ...]

and I would like to select lets say element 25-35.

I tried something like:

cubes[25-35].somefunction(); or cubes[25,26,27,28].somefunction();

but both does not work. How to do it?

Thanks

Answer:1

You need to slice the array by indices and then iterate over the elements in the result array and call the function on each element:

cubes.slice(25, 35).forEach(somefunction);

This assumes forEach is supported.

Otherwise,

var newArray = cubes.slice(25, 35);
for (var i=0; i < newArray.length; i++) {
   newArray[i].someFunction();
}

Finally, if even slice isn't available:

for (var i=firstIndex; i <= lastIndex; i++) {
       cubes[i].someFunction();
}
Answer:2

I want to use the Perf stuff. It seems that if I do: var React = require('react/addons'); in my own modules then libraries (react-bootstrap, react-router etc.) end up using another copy of plain ...

I want to use the Perf stuff. It seems that if I do: var React = require('react/addons'); in my own modules then libraries (react-bootstrap, react-router etc.) end up using another copy of plain ...

I'm trying to rewrite a C# function that uses yield and recursion to pull out instances of a class out of nested lists into a single list. This is the C# function: public static IEnumerable<...

I'm trying to rewrite a C# function that uses yield and recursion to pull out instances of a class out of nested lists into a single list. This is the C# function: public static IEnumerable<...

  1. typescript function in interface
  2. typescript function in class
  3. typescript function with return type
  4. typescript function with properties
  5. typescript function with any number of arguments
  6. typescript function with any arguments
  7. typescript function with parameters
  8. typescript function with optional parameter
  9. typescript function in object
  10. typescript function in enum
  11. typescript function with generics
  12. typescript function with variable number of arguments
  13. typescript function with default value
  14. typescript function with callback
  15. typescript function with return
  16. typescript function with any parameters
  17. typescript function with arguments
  18. typescript function with multiple parameters
  19. typescript function with generic type
  20. typescript function with different parameters

I have the following event-handling function: jQuery(document).on('click', '#button .submitb', function(e){alert();}); jQuery IS included in the html document. But, if I click on a <div id="...

I have the following event-handling function: jQuery(document).on('click', '#button .submitb', function(e){alert();}); jQuery IS included in the html document. But, if I click on a <div id="...

  1. jquery target selector

This may be a dumb question , not a completely programming related question but bear with me as I am trying to learn. How does FEEDLY retrive the feeds / news from a website just by entering the ...

This may be a dumb question , not a completely programming related question but bear with me as I am trying to learn. How does FEEDLY retrive the feeds / news from a website just by entering the ...

  1. what does service look like
  2. does honda have a service like onstar
  3. does jeep have a service like onstar