Recent | Popular
#html #javascript #jsfunctions #dom #dommanipulation
<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>
#javascript #json #jsfunctions
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);
#javascript #arrays #jsfunctions
const compact = arr => arr.filter(Boolean); compact([0, 1, false, 2, '', 3, 'a', 'e' * 23, NaN, 's', 34]);
#javascript #jsfunctions #numbers
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
#javascript #numbers #jsfunctions
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
Sun Jan 26 2020 21:18:49 GMT+0000 (UTC)
Sun Jan 26 2020 21:05:50 GMT+0000 (UTC)
Sun Jan 19 2020 18:56:05 GMT+0000 (UTC)
Sun Jan 19 2020 18:48:17 GMT+0000 (UTC)
Fri Jan 17 2020 20:33:47 GMT+0000 (UTC)
Fri Jan 10 2020 19:00:00 GMT+0000 (UTC)
Thu Jan 09 2020 19:00:00 GMT+0000 (UTC)
Wed Jan 08 2020 19:00:00 GMT+0000 (UTC)
Tue Jan 07 2020 19:00:00 GMT+0000 (UTC)