Manipulating object objects in JS

Source: Internet
Author: User

n =for (var in N) {    console.log (p); //    obtained is the key value    Console.log (n[p]);   get is value }

Following the usual methods of arrays in JS, the common methods and properties of object are often used. So, summarize it.
First, the attribute
Object comes with a prototype attribute, that is, Object.prototype,object.prototype itself is an object, and there are properties and methods. As follows:
1. Properties
Object.prototype.writable: Default is False
Object.prototype.enumerable: Default is False
Object.prototype.configurable: Default is False
Object.prototype.constructor: The prototype used to create an object.
2. Common methods
Object.prototype.hasOwnProperty (): Returns a Boolean value that indicates whether an object contains the specified property, and this property is not inherited by a prototype chain.

Object.prototype.isPrototypeOf (): Returns a Boolean value that indicates whether the specified object is in the prototype chain of this object.

Object.prototype.propertyIsEnumerable (): Determines whether the specified property can be enumerated.

Object.prototype.toString (): Returns the string representation of the object.

Object.prototype.watch (): Adds a listener to an object's properties.

Object.prototype.unwatch (): Removes the listener for a property of an object.

Object.prototype.valueOf (): Returns the original value of the specified object.

Second, the method
Object.assign (target, ... sources): Copies the enumerable properties of any number of source objects themselves to the target object, and then returns the target object.

Object.create (Proto,[propertiesobject]): Creates an object that has a specified prototype and several specified properties.

Object.defineproperties (obj, props): Adds or modifies one or more own properties on an object and returns the object.

Object.defineproperty (obj, prop, descriptor): Defines a new property directly on an object, or modifies an already existing property and returns the object. OBJ: An object that needs to define a property. Prop: The name of the property that needs to be defined or modified. Descriptor: The descriptor of the property that will be defined or modified.

Object.entries (obj): Returns an array of property names, property values, and key-value pairs that consist of the property names and property values of all enumerable properties of a given object, the order in which the key-value pairs are arranged in the array, and the order that is returned when iterating through the object using the for...in loop.
Example:
var obj = {foo: "Bar", baz:42};
Console.log (object.entries (obj)); [[' foo ', ' Bar '], [' Baz ', 42]]

Object.freeze (obj): Freezes an object, which means that a new property cannot be added to the object, the value of its existing property cannot be modified, the existing attribute cannot be deleted, and the enumerable, configurable, and writable properties of an existing property cannot be modified. In other words, this object is always immutable. The method returns the object that was frozen.

Object.getownpropertydescriptor (obj, prop): Returns the property descriptor corresponding to a property on the specified object.

Object.getownpropertynames (obj): Returns an array of property names (including non-enumerable properties) of all the properties of the specified object.
Example:
Class Array Object
var obj = {0: "A", 1: "B", 2: "C"};
Console.log (Object.getownpropertynames (obj). sort ()); ["0", "1", "2"]

Object.getprototypeof (object): Returns the prototype of the object.

Object.is (value1, value2): Determines whether two values are the same value.

Object.isextensible (obj): Determines whether an object is extensible (whether a new property can be added to it).

Object.isfrozen (obj): Determines whether an object is frozen (frozen).

Object.issealed (obj): Determines whether an object is sealed (sealed). Sealed objects are objects that are not extensible and are not configurable by all of their properties (non-configurable) and cannot be deleted (which can be writable).

Object.keys (obj): Returns an array of property names for all enumerable properties of the given object, the order in which the property names are arranged in the array, and the order in which they are returned when iterating through the object using the For-in loop
Example:
var arr = ["A", "B", "C"];
Alert (Object.keys (arr)); Pop Up "0,1,2"

Class Array Object
var obj = {0: "A", 1: "B", 2: "C"};
Alert (Object.keys (obj)); Pop Up "0,1,2"

Object.preventextensions (obj): Make an object non-extensible, that is, you can never add new properties.

Object.setprototypeof (obj, prototype): Sets the prototype of a specified object to another object or null

Object.values (obj): Returns an array containing the values of the enumerable properties of the specified object, the order of values in the array, and the order in which they are traversed using the for...in loop.
Example:
var obj = {foo: "Bar", baz:42};
Console.log (object.values (obj)); [' Bar ', 42]

Manipulating object objects in JS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.