//年月提取
var dateItem = "2010/10/23";
var yearid="",monthid="";
function getYearDate(data){
yearid = data.split("/")[0];
monthid = data.split("/")[1];
}
var c = new getYearDate(dateItem);
console.log("dateItem",yearid,monthid)
//取出两个数组的不同元素
var arr1 = [0,1,2,3,4,5];
var arr2 = [0,4,6,1,3,9];
function getArrDifference(arr1, arr2) {
return arr1.concat(arr2).filter(function(v, i, arr) {
return arr.indexOf(v) === arr.lastIndexOf(v);
});
}
console.log("getArrDifference",getArrDifference(arr1,arr2));
//取出两个数组的相同元素
var arr3 = [0,1,2,3,4,5];
var arr4 = [0,4,6,1,3,9];
function getArrEqual(arr3, arr4) {
let newArr = [];
for (let i = 0; i < arr4.length; i++) {
for (let j = 0; j < arr3.length; j++) {
if(arr1[j] === arr4[i]){
newArr.push(arr3[j]);
}
}
}
return newArr;
}
console.log("getArrEqual",getArrEqual(arr3, arr4));
//两个数组差集
let a=[{id:1,a:123,b:1234},{id:2,a:123,b:1234}];
let b=[{id:1,a:123,b:1234},{id:2,a:123,b:1234},{id:3,a:123,b:1234},{id:4,a:123,b:1234}];
let arr = [...b].filter(x => [...a].some(y => y.id === x.id));
console.log("arr",JSON.stringify(arr))
function getDifferentArr (allArr, partArr) {
for (let i = allArr.length - 1; i >= 0; i--) {
for (let j = 0; j < partArr.length; j++) {
if (allArr[i].id === partArr[j].id) {
allArr.splice(i, 1);
break;
}
}
}
return allArr;
}
//计算数组元素相加后的总和:
var numbers = [65, 44, 12, 4];
function getSum(total, num) {
return total + num;
}
function myFunction(item) {
document.getElementById("demo").innerHTML = numbers.reduce(getSum);
}
console.log( Math.abs(0.1 + 0.2 - 0.3) <= Number.EPSILON);
//数组去重
function getFilterArray(array){
const set = new Set(array);
return [...set];
}
console.log("getFilterArray",getFilterArray([1,2,2,3,4,5,4,6,]))
var arrObject = [{'brand':'可乐','price':3,'year':2021},{'brand':'薯片','price':7,'year':2020},{'brand':'朗姆酒','price':200,'year':1999},{'brand':'薯条','price':7,'year':2021},{'brand':'营养快线','price':5,'year':2021}];
var len = arrObject.length;
var point = null;
for(var i=0; i<arrObject.length;i++){
point = i;
for(var j=i+1;j<arrObject.lenth;j++){
if(arrObject [pont]['price'] > arrObject[j]['price']){
point = j;
}else if(arrObject[point]['price'] > arrObject[j]['price'] && arrObject[point]['year'] < arrObject[j]['year']){
point = j;
}
}
var temp = arrObject[i];
arrObject[i] = arrObject[point];
arrObject[point] = temp;
}
var letarry=[1,2,3,4,5,6,7,8];
for(let i=0;i<letarry.length;i++){
console.log(i)
}
function openListUlr(brandid, brandname, seriesid, sname, pid, cid, pvid, url, ispc, infoids = '', isoutsite, sourceid, priceregion = '', agerange = '', mileage = '', fromtype = '') {
let jumpUrl = '';
let para = {
"title": "列表页",
"pid": pid + "",
"cid": cid + "",
"brandid": brandid + "",
"seriesid": seriesid + "",
"pvareaid": pvid + "",
}
if (+isoutsite > 0) {
para.isoutsite = `${isoutsite}`;
}
if (+sourceid > 0) {
para.sourceid = `${sourceid}`;
}
if (`${infoids}`.length > 0) {
para.infoid = `${infoids}`;
}
if (priceregion.length > 0) {
para.priceregion = priceregion;
}
//添加车龄传参
if (agerange.toString().length > 0) {
para.registeageregion = agerange;
}
//添加里程传参
if (mileage.toString().length > 0) {
para.mileageregion = mileage;
}
if (+fromtype > 0) {
para.fromtype = `${fromtype}`;
}
jumpUrl = `${SCHEME.USEDCAR}/rnhomegobuycar?param=${encodeURIComponent(JSON.stringify(para))}`
console.log(jumpUrl + '--' + JSON.stringify(para));
}
var friend={
firstName: 'Good',
'lastName': 'Man',
'address': undefined,
'phone': ["1234567",undefined],
'fullName': function(){
return this.firstName + ' ' + this.lastName;
}
};
JSON.stringify(friend)
console