[Vuejs]-VueJs How to Split string from a variable in API

0๐Ÿ‘

โœ…

If the data gives you the Array of Object from the JSON, then you can have a function like this when you loop through the array;

saveObject: function(object){
  var latLngArray = object.geo.split(', ');
  object["lat"] = latLngArray[0];
  object["lng"] = latLngArray[1];
}

and in your setProperty function, you can call it like this

setProperty(data){
   var arrayProperty = [];
   var self = this;
   data.forEach(function(item){
      arrayProperty.push(self.saveObject(item));
   })
   this.property = arrayProperty;
}

The saveObject function will manipulate the data you pass in. This is not the ideal way. it is better to just create a variable that is the same as the passed in object and just return that variable

Leave a comment