Requirements: object to a string and | splicing

data: { 
 id: 1,
 id2: 3
}
Copy the code

Solutions:

// The first step is to convert to an array
var list=[];
for(var i in data){ 
  list.push(i) 
  list.push(data[i]) 
}
console.log(list)
// The second step is to convert the array to string concatenation
var listStr="";
listStr=list.join('|') 
console.log(listStr) 
Copy the code

An array of the same