Skip to content

Instantly share code, notes, and snippets.

View Paul-Browne's full-sized avatar
🏠
Working from home

Paul Browne Paul-Browne

🏠
Working from home
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
body{
margin: 0;
}
//todo
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
var daysCopy = days;
days.push("Saturday", "Sunday");
daysCopy[0] = "Lundi";
console.log(days);
// ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
var daysCopy = days.slice();
days.push("Saturday", "Sunday");
daysCopy[0] = "Lundi";
console.log(days);
// ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
console.log(daysCopy);
var array = [1, 2, [3, 4], [5, 6, [7, 8], 9], 10];
var string = array.toString();
console.log(string);
// 1,2,3,4,5,6,7,8,9,10
var array = ["Monday", "Tuesday", "Wednesday"];
array.name = "Paul";
array.age = 35;
console.log(array);
// ["Monday", "Tuesday", "Wednesday", name: "Paul", age: 35]
console.log(array.length);
// 3
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
days.forEach( (element, index) => {
console.log(element, index);
})
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Saturday", "Sunday"];
if( days.indexOf("Wednesday") > -1 ){
console.log("contains Wednesday!");
}
// same as
var containsWednesday = days.some(function(element){
return element === "Wednesday";
});
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Saturday", "Sunday"];
var removed = days.splice(4, 2, "Friday");
console.log(days);
// ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
console.log(removed);
// [Saturday, Sunday]
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
var copy = days.slice();
var weekend = days.slice(5);
var alsoWeekend = days.slice(-2);
var weekdays = days.slice(0, 5);
var alsoWeekdays = days.slice(0, -2);
console.log(copy);
// ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
var weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
var eg1 = weekdays.join();
var eg2 = weekdays.join("");
var eg3 = weekdays.join(" + ");
console.log(eg1);
// "Monday,Tuesday,Wednesday,Thursday,Friday"
console.log(eg2);