Skip to main content

JSON

JSON


var obj = {"name": "Hari", "city":"Trichy,"Mother Tongue":"Tamil"}
var obj1 = [{name:"book" ,price:100},{name:"note" ,price:50},{name:"pen" ,price:10},{name:"pencil" ,price:5}]


var obj2 = {"name":"santhosh" ,"marks":[89,90,95,100]}

var arr = [1,2,3,4,5,6]

ARRAY METHOD / JSON ARRAY

FILTER

arr.filter((item)=>item<4//[1,2,3]
function even (num){if(num%2==0return "even"}
arr.filter((even)) // [2,4]
obj1.filter((item)=>item.price<=10) [{ name: "pen"price: 10 },{ name: "pencil"price: 5 }]

MAP

arr.map((item)=>item+1// [2,3,4,5,6,7]
obj1.map((item)=>item.name// [ "book", "note", "pen", "pencil" ]

REDUCE

arr.reduce((currentvalue,item)=>currentvalue+item,0//21 // 0 is my current value

With reduce method we can perform add,sub,mul and divison

SOME,EVERY,INCLUDES

arr.some((item)=>item==4// true
obj1.some((item)=>item.name=="book"//false
arr.every((item)=>item==4// false
obj1.every((item)=>item.name=="book"//false
arr.includes(2// true //simillar to some

Comments

Popular posts from this blog

  You are provided with the radius of a circle "A". Find the length of its circumference. Note: In case the output is coming in decimal, roundoff to 2nd decimal place. In case the input is a negative number, print "Error". function   coc () { var   r = document . getElementById ( "num1" ). value ; var   pi = 3.1415 ; var   Circumference =( 2 * pi * r ); if  ( r >= 0 ) console . log ( Circumference ); else console . log ( "Error" )} 
The area of an equilateral triangle is ¼(√3a 2 ) where "a" represents a side of the triangle. You are provided with the side "a". Find the area of the equilateral triangle. function   sqrt () { var   a = document . getElementById ( "a" ). value ; b =  Math . sqrt ( 3 ); c =( 1 / 4 )* b * a * a ; console . log (  "Area =" + c )}

HOISTING

  HOISTING Variables” and “ function” declarations are moved to the top of their scope before code execution. Variables are hosted and not their values Only the normal function will be hoisted not the anonymous,IIFE and Arrow Function will be hoisted Properties are not hoisted PROPERTY  Any variable declared globally  become property of window variable declared without keyword variable declared with keyword var except function scope var console . log ( a )   // Error a not defined console . log ( a );  // undefined --> var a is hoisted not value var   a  =  20 ; console . log ( a , b )  // Error --->property b can't hoist var   a  =  20 ; b  =  40 ; var   a  = add ( 2 , 5 )  // Error console . log ( a ) var   a  = add ( 2 , 5 )  // 7 function add hoist console . ...