Skip to content

Instantly share code, notes, and snippets.

@rodrigo-brito
Last active January 31, 2017 10:51
Show Gist options
  • Save rodrigo-brito/b0f3c8a19ccdde11221318090686e51f to your computer and use it in GitHub Desktop.
Save rodrigo-brito/b0f3c8a19ccdde11221318090686e51f to your computer and use it in GitHub Desktop.
Native operations with JS
var node = document.createElement("LI"); // Create a <li> node
var textnode = document.createTextNode("Water"); // Create a text node
node.appendChild(textnode); // Append the text to <li>
document.getElementById("myList").appendChild(node); // Append <li> to <ul> with id="myList"
var teste = document.querySelector("#teste");
var element = document.getElementById("element-id");
element.outerHTML = "";
delete element;
var str = "How are you doing today?";
var res = str.split(" ");
var str = "Visit Microsoft!";
var res = str.replace("Microsoft", "W3Schools");
var fruits = ["Banana", "Orange","Apple", "Mango"];
var join = fruits.join(" * "); //Banana * Orange * Apple * Mango
fruits.pop(); // Removes the last element ("Mango") from fruits
fruits.push("Kiwi"); // Adds a new element ("Kiwi") to fruits
fruits.shift(); // Removes the first element "Banana" from fruits
fruits.unshift("Lemon"); // Adds a new element "Lemon" to fruits
fruits.sort(); // Sorts the elements of fruits
fruits.reverse(); // Reverses the order of the elements
var myGirls = ["Cecilie", "Lone"];
var myBoys = ["Emil", "Tobias","Linus"];
var myChildren = myGirls.concat(myBoys); // Concatenates (joins) myGirls and myBoys
document.getElementById("demo").innerHTML = fruits.toString();
var ages = [32, 33, 12, 40];
var maior = ages.filter(function (age) {
return age >= 18;
});
var d = new Date();
var d = new Date(milliseconds);
var d = new Date(dateString);
var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment