JS removes duplicate values from the array

Source: Internet
Author: User
Tags hasownproperty

hasOwnProperty (property) method

The hasOwnProperty function method in JavaScript is to return a Boolean value that indicates whether an object has a property of the specified name. How to use:

object.hasOwnProperty(proName)

Where the Parameter object is a required option. An instance of an object.
Proname is a mandatory option. A string value for the name of a property.

If object has a property of the specified name, then the hasOwnProperty function method in JavaScript returns True, and vice versa. This method cannot check whether the object has this property in its prototype chain, and the property must be a member of the object itself. In the following example, all the String objects share a common split method.

var s=New String ("j,script"); alert (S.hasownproperty ("  split"));  // falsealert (String.prototype.hasOwnProperty ("split"));  // true

Array de-weight JS

<script>//using the properties of the JS object, create a new empty object, add the element in a as an attribute to the object, and detect if the property already exists before adding it. a=[0,8,5,4, +,8, -,4,'a','b','a','C','D','C',1,3,2,3,4];function gn (SRC) {//src =src | | [];varres = {};varCurr = [];varI, j =0, temp, name; for(i =0; i < src.length; i++) {Temp=Src[i];if(Res[temp]) {//Do noting}Else{Res[temp]=1;}} for(NameinchRes) {if(Res.hasownproperty (name)) {//is used to determine whether an object has a property or object that you give a name to. However, it is important to note that this method cannot check whether the object has this property in its prototype chain, and that the property must be a member of the object itself. Curr[j++] =name;}}alert (curr);}</script>

 

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.