Snippets Collections
<html>

<input id="contact" name="address">

<script>

    var x = document.getElementById("contact").getAttribute('name');

</script>

</html>
<html>	
   
   <input id="contact" name="address">
 
 <script>

    document.getElementById("contact").attribute = "phone";
	
    //ALTERNATIVE METHOD TO CHANGE
    document.getElementById("contact").setAttribute('name', 'phone');	

  </script>

</html>
var profile = {
  name: 'John',
  age: 25,
  isAdmin: false,
  courses: ['html', 'css', 'js']
};

var person = JSON.stringify(profile);
var contacts = '{ "people" : [' +
'{ "firstName":"Joe" , "lastName":"Smith" },' +
'{ "firstName":"Tom" , "lastName":"Hardy" },' +
'{ "firstName":"Ben" , "lastName":"Stiller" } ]}';

var newObject = JSON.parse(contacts);

const compact = arr => arr.filter(Boolean);

compact([0, 1, false, 2, '', 3, 'a', 'e' * 23, NaN, 's', 34]); 
var x = 1.234;
 
var y = x.toExponential(2); 
// returns y = 1.23e+0
 
var y = x.toExponential(5);  
// returns y = 1.23450e+0
parseInt("10");         // returns 10
parseInt("10.33");      // returns 10
parseInt("10 20 30");   // returns 10
parseInt("10 years");   // returns 10
parseInt("years 10");   // returns NaN 
var x = 1.2345;

var y = x.toFixed(0);
//y equals 1;

var y = x.toFixed(2);
//y equals 1.23

var y = x.toFixed(5);
//y equals 1.23400
var x = 123;

//OPTION 1
var y = x.toString();           

//OPTION 2
var y = (123).toString();        

//OPTION 3
var y = (100 + 23).toString();   

// value of y is 123 in all 3 cases.
var x = 1234;
var y = x.valueOf(); 

var y = (1234).valueOf();

var y (1000+234).valueOf();

//y equals 1234 in all 3 cases
bookmark
dashboard

Sun Jan 19 2020 18:56:05 GMT+0000 (UTC)

#javascript #json #jsfunctions
bookmark
dashboard

Sun Jan 19 2020 18:48:17 GMT+0000 (UTC)

#javascript #json #jsfunctions
bookmark
dashboard

Fri Jan 17 2020 20:33:47 GMT+0000 (UTC)

#javascript #arrays #jsfunctions
bookmark
dashboard

Fri Jan 10 2020 19:00:00 GMT+0000 (UTC)

#javascript #jsfunctions #numbers
bookmark
dashboard

Wed Jan 08 2020 19:00:00 GMT+0000 (UTC)

#javascript #numbers #jsfunctions

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension