One, dealing with arrays

1.JavaScript retrieves an object’s index in an array based on an attribute

let arr=new Array({"name":"wxx","age":2},{"name":"yier","age":6});

let index=arr.findIndex(function(item){
    return item.name===='yier'
})
console.log(index)
Copy the code

Two, work with strings

1. Intercept the characters after commas in the string

function getCaption(obj){ var index=obj.lastIndexOf("\,"); obj = obj.substring(index+1,obj.length); return obj; } var STR ="dsafas "; getCaption(str); console.log(getCaption(str)); // Style is not djsld13Copy the code

2. Handle links

function GetRequestParams(hrefUrl){ let href=hrefUrl; let localhref=href; If (href. IndexOf ('#/')! ==-1){ let reg=new RegExp('#/') localhosthref=href.replace(reg,''); } let localarr; if(localhref.split('? ')[1]){ localarr=localhref.split('? ')[1].split('&') } if(! localarr){ return null; } var tempObj={}; for(let i=0; i<localarr.length; i++){ tempObj[localarr[i].split('=')[0]]=localarr[i].split('=')[1] } return tempObj; }Copy the code