let obj = {
results: {
bindings: [
{ placeName: 'cali', lat: '123', long: '456' },
{ placeName: 'hawaii', lat: '555', long: '333'},
{ placeName: 'korea', lat: '777', long: '888' }]
}
};
let markers = [];
obj.results.bindings.forEach(item => {
let mar = { content: '', coords: {}};
mar.content = item.placeName;
mar.coords.lat = Number(item.lat);
mar.coords.lng = Number(item.long);
markers.push(mar)
})
console.log(markers)
如何将var string1 = "Hello, World";
var arr = string1.split(",");
var string2 = "Hello World";
数组的值与变量arr
的值进行比较?
答案 0 :(得分:1)
只需使用join
方法,如下所示:
var string1 = "Hello, World";
var arr = string1.split(",");
var string2 = "Hello World";
var arr_string = arr.join('');
console.log(arr_string == string2);
或者您可以尝试replace
,如下所示:
var string1 = "Hello, World";
var string2 = "Hello World";
var new_string1 = string1.replace(/,/g, '');
console.log(new_string1 == string2);