This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]; | |
days.forEach( (element, index) => { | |
console.log(element, index); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
NewerOlder