JS Common array of programming operations

Source: Internet
Author: User
First, find the position of the element item in the given array arr, otherwise return-1


Find robust code for the position of an element two, calculate the sum of the given array elements (the element is number type)

There are many ways to do this, such as regular loops, recursion, foreach traversal, reduce accumulation, or even eval ().


Reduce is a special additive for the three, copy array


Slice (0) method is the simplest four, do not modify the original array, delete the same as the array value of the specified element


The easiest way to do this without modifying the original array is to use Fliter to return the filtered array

* In the above method, the push method and the Splice method will modify the called array itself, if the subject changes directly, then do not need to copy the original array and then perform the operation.

Add elements after the array and do not modify the array directly


Vi. Delete the last element without directly modifying the array


Merge arrays, do not modify arrays directly


Viii. the number of occurrences of the specified item in the statistics array


Nine, find repeating elements


Ten, ask for two Times Square


Xi. in the array arr, find all the locations where the element with the value equal to item appears


JS Common array of programming operations

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.