Answers for "javascript collections"

0

javascript access collections of elements

<div class="wrapper">
  <p class="box">Food</p>		<!-- Index Position 0 -->
  <p class="box">Drink</p>		<!-- Index Position 1 -->
  <p class="box">Books</p>		<!-- Index Position 2 -->
  <p class="box">Whatever</p>	<!-- Index Position 3 -->
</div>

<script>
var myCollection = document.getElementsByClassName("box");
console.log(myCollection)
myCollection[0].innerHTML = "I can change everything!"
</script>
Posted by: Guest on November-10-2020
0

js collection

//There are 3 types of Collections in Javascript:
//-Indexed Collections
//-Keyed Collections
//-DOM Collections

// Elements are based on index values - in JavaScript starting from 0.
var indexed = [] 		
// Elements are based on key-value pairs 
var keyed = {} 		
// HTML elements, based on index values, starting from 0.
let DomCollection = document.getElementsByTagName("p");
Posted by: Guest on October-05-2021

Browse Popular Code Answers by Language