Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get methods on an js object

let members = Object.getOwnPropertyNames(foo)
Comment

methods of object js

create()
keys()
values()
entries()
assign()
freeze()
seal()
getPrototypeOf()
Comment

JavaScript Object Methods

const person = {
  firstName: "John",
  lastName: "Doe",
  id: 5566,
  fullName: function() {
    return this.firstName + " " + this.lastName;
  }
};
Comment

JavaScript Object Methods

const person = {
    name: 'Sam',
    age: 30,
    // using function as a value
    greet: function() { console.log('hello') }
}

person.greet(); // hello
Comment

javascript get object methods

 for (let key in object) {
    console.log(key);
    console.log(object[key]);
  }
Comment

object methods

//There are 2 main ways to create an Object in JavaScript

//The First Method:
let firstPlayer = new Object();

//You can add properties like this:
firstPlayer.name = 'Player 1';
firstPlayer.level = 3;
firstPlayer.inventory = ['a half-eaten cracker', 'some pocket lint', 'a flimsy tree branch'];
firstPlayer.description = 'Don't mention Player 2 around them, they'll get angry...';

//You can create methods like this:
firstPlayer.checkLevel = function() {
    console.log(`${this.name} is currently... Level ${this.level}!`);
    //The "this" keyword refers to the object
}

firstPlayer.checkLevel();
//This will print "Player 1 is currently... Level 3!" to the Console


//The Second Method:
let secondPlayer = {
    
    //You can add properties like this:
    name: 'Player 2',
    level: 20,
    inventory: ['a health potion', 'a sack of gold coins', 'a sturdy steel blade'],
    description: 'Better than Player 1 in every way possible.',
    
    //You can create methods like this:
    checkLevel: function() {
        console.log(`${this.name} is currently... Level ${this.level}!`);
        //The "this" keyword refers to the object
    }
}

secondPlayer.checkLevel();
//This will print "Player 2 is currently... Level 20!" to the Console

//And that's it! Decide what method you prefer and start making some Objects!
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript object loop 
Javascript :: repeat a function javascript 
Javascript :: javascript append html 
Javascript :: jquery ui dialog position fixed center 
Javascript :: cypress multiple true 
Javascript :: golang json omitempty struct 
Javascript :: JavaScript querySelector - By ID 
Javascript :: for of loop 
Javascript :: how to disable link in react 
Javascript :: javascript fetch request GET 
Javascript :: get an element from outside of iframe jquery 
Javascript :: how to print a pdf 
Javascript :: xor in javascript 
Javascript :: get element by name in jquery 
Javascript :: javascript allow default 
Javascript :: ajax data not reflecting after refresh particular div jquery 
Javascript :: what does getattribute return null for data-* attributes 
Javascript :: print first n prime numbers in javascript 
Javascript :: javascript number in alphabet 
Javascript :: vue localstore 
Javascript :: run node js 
Javascript :: js remove specific item from array 
Javascript :: angular conditionally show tooltip 
Javascript :: async function javascript 
Javascript :: array find 
Javascript :: current date in mongodb 
Javascript :: how to assert in javascript 
Javascript :: console log vuex in production 
Javascript :: local storage in vanila javascript 
Javascript :: javascript change content of h element 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =