Create Removing duplicate element from array in Javascript

View: 338    Dowload: 0   Comment: 0   Post by: hanhga   Category: Javascript   Fields: Other

8 point/2 review File has been tested

What is an array ?

In javascript it is called objects, it is also called data structures

With the help of an array we can store multiple values in a single variable

Array stores values in it’s index location

Array uses indexes for storing values, that indexes start from 0 (zero) and so on

Every value which stored in an array has its specific location

The values store in an array are called array elements

It is very useful for real web applications, for instance we can store users, products, country names etc

By default duplicate elements can be stored in an array

Following code snippet will guide you for removing duplicate elements from an array in Javascript.

<script>
 
function removeDuplicates(arr) { // declare a function, pass an array as an parameter
var temp = {};  // declare empty variable for a temporary storage
for (var i = 0; i < arr.length; i++) // loop through each array elements
temp[arr[i]] = true;
 
var r = []; // declare an empty array
for (var k in temp) // loop through each array element
r.push(k); // array's push(method), this function adds new item to an array
return r; // return variable for rendering the output
}
 
//Usage
var fruits = ['apple', 'orange', 'peach', 'apple', 'strawberry', 'orange']; // create an array with name fruits with 6 elements, there are orange and apple 2 duplicate elements
var uniquefruits = removeDuplicates(fruits); // call above function and pass an array as a argument to that function
//print uniquefruits ['apple', 'orange', 'peach', 'strawberry']; // this is the output on your browser
 
</script>

Create Removing duplicate element from array in Javascript

Create Removing duplicate element from array in Javascript Posted on 29-08-2016  With the help of an array we can store multiple values in a single variable 4/10 338

Comment:

To comment you must be logged in members.

Files with category

  • AngularJS and REST API

    AngularJS and REST API

    View: 57    Download: 0   Comment: 0

    Category: Javascript     Fields: Other

    This is a tutorial for those interested in a quick introduction to AngularJS and REST API. We will build the familiar Periodic Table of the Elements found in every chemistry textbook, and allow the user to select a Chemical Element by clicking on...

  • Collective Intelligence, Recommending Items Based on Similar Users' Taste

    Collective Intelligence, Recommending Items Based on Similar Users' Taste

    View: 85    Download: 0   Comment: 0

    Category: Javascript     Fields: Other

    Using Collaborative Filtering to find people who share tastes, and for making automatic recommendations based on things that other people like.

  • Think Like a Bird for Better Parallel Programming

    Think Like a Bird for Better Parallel Programming

    View: 57    Download: 0   Comment: 0

    Category: Javascript     Fields: Other

    Coding an application to run in parallel is hard, right? I mean, it must be hard or we’d see parallel programs everywhere. All we'd see are slick parallel apps that use every available core effortlessly. Instead multi-threaded apps are the exception...

  • Getting Started with the Bing Search APIs

    Getting Started with the Bing Search APIs

    View: 64    Download: 0   Comment: 0

    Category: Javascript     Fields: Other

    Bing Search API is a set of REST interfaces that find web pages, news, images, videos, entities, related searches, spelling corrections, and more in response to queries from any programming language that can generate a web request. Applications that...

  • Brief Introduction of SocketPro High Performance and Scalable Persistent Message Queue

    Brief Introduction of SocketPro High Performance and Scalable Persistent Message Queue

    View: 260    Download: 0   Comment: 0

    Category: Javascript     Fields: Other

    Continuous in-line request/result batching, real-time stream sending/processing, asynchronous data transferring and parallel computation for best performance and scalability

  • Iteration Over Java Collections with High Performance

    Iteration Over Java Collections with High Performance

    View: 53    Download: 0   Comment: 0

    Category: Javascript     Fields: Other

    Java developers usually deal with Collections such as ArrayList, HashSet, Java 8 come with lambda and streaming API helps us to easily work with Collections. In most cases, we work with few thousands of items and performance isn't a concern. But in...

  • SR2JLIB - A Symbolic Regression Library for Java

    SR2JLIB - A Symbolic Regression Library for Java

    View: 58    Download: 0   Comment: 0

    Category: Javascript     Fields: Other

    Grammar-Guided Genetic Programming library featuring: multi-threading, just-in-time compilation of individuals, dynamic class loading, and JNI interfacing with C/C++ code

  • Yet Another Fluent JDBC Wrapper in 200 Lines of Code

    Yet Another Fluent JDBC Wrapper in 200 Lines of Code

    View: 72    Download: 0   Comment: 0

    Category: Javascript     Fields: Other

    Those who are not convinced to use Hibernate to manage persistence are forced to use plain old JDBC API. Though powerful, it requires lot of typing to get it right. For example, retrieving user data from database often requires such code snippet:

 
File suggestion for you
File top downloads
Codetitle.net - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.net Develope by Vinagon .Ltd