In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces JavaScript array, string and mathematical function example analysis related knowledge, detailed and easy to understand, simple and fast operation, has a certain reference value, I believe everyone will read this JavaScript array, string and mathematical function example analysis article will have some gains, let's take a look at it.
The push() method adds one or more elements to the end of the array and returns the new length of the array (the length attribute value).
The pop() method removes the last element of an array and returns it.
The shift() method removes the first element of the array and returns it. This method changes the length of the array.
The unshift() method adds one or more elements to the beginning of the array and returns the new length value of the array.
The join() method joins all elements of an array into a string.
The **split()** method splits a String object into an array of strings by splitting the string into substrings.
code problem
array
Push, pop, shift and unshift methods implemented with splice
definition and use
The splice() method is used to insert, delete, or replace elements of an array.
syntax
arrayObject.splice(index,howmany,element1,....., elementX)
parameter description
Index is required. Specify where elements are added/removed from. This parameter is the subscript of the array element to start inserting and/or deleting. It must be a number.
How many are necessary. Specify how many elements should be removed. Must be a number, but can be "0." If this parameter is not specified, all elements from index to the end of the original array are deleted. element1 is optional. Specifies the new element to add to the array. Insert from index.
elementX is optional. Several elements can be added to an array.
return value
If an element is deleted from an arrayObject, an array containing the deleted element is returned.
splice->push
vara=[1,2,3,4,5]
varb=[1,2,3,4,5]
console.log(a);
console.log(b);
a.push(6);
b.splice(5,1,6);
console.log(a);
console.log(b);
splice->pop
vara=[1,2,3,4,5]
varb=[1,2,3,4,5]
console.log(a);
console.log(b);
a.pop();
b.splice(4,1);
console.log(a);
console.log(b);
splice->shift
vara=[1,2,3,4,5]
varb=[1,2,3,4,5]
console.log(a);
console.log(b);
a.shift();
b.splice(0,1);
console.log(a);
console.log(b);
splice->unshift
vara=[1,2,3,4,5]
varb=[1,2,3,4,5]
console.log(a);
console.log(b);
a.unshift(-1);
b.splice(0,0,-1);
console.log(a);
console.log(b);
Use arrays to concatenate the following strings
varprod={name:'women', styles: <$'short','winter',' spring']
};functiongetTpl(data){//todo...}; varresult=getTplStr(prod);//result is the following string
Women's dress
short
winter
spring clothes
Code:
varprod={
name:'women',
styles: "'Short ',' Winter ',' Spring ']
};
functiongetTplStr(data){
varhtmls=[];
htmls.push('',''+data,name+'');
for(i=0;i
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.