Guest User

Untitled

a guest
Jun 24th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. //When you commonly declare an array variable in JS
  2. var questionsList=[];
  3.  
  4. //And now you want to push an element into it using for loop
  5. for(var i=0; i<someVar.length; i++) {
  6. questionsList.push(someVar[i].question);
  7. }
  8.  
  9. //If you would like to remove some index, then first take the index
  10. var index = wrapList.indexOf(0);
  11. wrapList.splice(index,1);
  12. //Above the second param basically tells to remove one element from the 0 index, if you give it 2, it will remove two elements, keep it 1
  13.  
  14. //Now consider you wanted to declare a variable in JS with a key and a value, then you would have declared like this:
  15. var wrapList = [{label="", value=""}, {label="", value=""}];
  16. //However, above just can have two elements when you push some value into it
  17. wrapList[0].label = 'test';
  18. wrapList[0].value = 'testvalue';
  19. wrapList[1].label = 'test1';
  20. wrapList[1].value = 'test1value';
  21. //You can ofcourse try creating a map variable in JS dynamically, i am still to figure out that, but do hit me with comments on it, if you know
Add Comment
Please, Sign In to add comment