Skip to content

Instantly share code, notes, and snippets.

@PatrickKyei
Last active July 30, 2018 10:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatrickKyei/0b46894e378e1f25bba24763a64aa22d to your computer and use it in GitHub Desktop.
Save PatrickKyei/0b46894e378e1f25bba24763a64aa22d to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/joviqok
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script>
var People= {
Persons: ['John', 'Bob'],
displayPersons: function(){
console.log(this.Persons.toString());
},
addFirstPerson: function(name){
this.Persons.unshift(name);
this.displayPersons();
},
removeFirstPerson: function(){
this.Persons.shift();
this.displayPersons();
},
removeLastPerson: function(){
this.Persons.pop();
this.displayPersons();
},
addLastPerson: function(name){
this.Persons.push(name);
this.displayPersons();
},
addSpecificPerson: function(position,name){
this.Persons.splice(position,0,name);
this.displayPersons();
},
removeSpecificPerson: function(position,remove){
this.Persons.splice(position,remove);
this.displayPersons();
},
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment