0% found this document useful (0 votes)
5 views1 page

Notes JS-5

Uploaded by

jtomm2covj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Notes JS-5

Uploaded by

jtomm2covj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Or

Emparray.indexOf(“suresh”) >= 0 // checking t/f

How to simply write a array with 1 to 200 numbers in it


const array = Array.from(Array(200).keys());

dynamic value ` somestring sfs fsf vd f dg dg ${variable} lmfksn gne segn k `

ways to itearate through dict in JS


let dict = {key1 : val1, key2 : val2 …… }
Object.entries() function converts dict into array of arrays
for( const [key, value] of Object.entries(dict) ) {
// work with key and value }
2) for ( var key in dict ) {
You will get keys and you can get value using dict[key] }
3)

Ways to iterate through array in JS


Let array1 = [“one”, “two”, three]
1) For( let i=0; I < array1.length ; i++ ) { array1[i]
2) Array1.forEach( (eachElement, index) => { …..}
3) Array1.every( eachElement => ….. ). Here every method will check if
all the elements pass the test provided in the call back function
4) For( let [index, value] of array1.entries() ) { .. work with index, value }
5) For (const eachindex in array1 ) { you can get value form index …. }
6) For ( const eachvalue of array1 ) { you can get value directly … }

***For laying out the elements in React we use the map method for array and
for dict we will extract the Object.Keys(dict) as an array and then we will apply
map method

In JS values extracted from input field will always be a string, even though you
mention the type as number, event.target.value will always be a string
Hence always convert to number Number(event.target.value) , or simply
+(event.tatget.value)
100 + “100” = 10000

Difference between settimeout and setinterval

You might also like