// mock data i get form server - backend
function getFriendData(){
var friendDataFromServerInJSON = [
{id: 22, name: "Tom"},
{id: 23, name: "Sam"},
{id: 24, name: "Kim"}
];
return friendDataFromServerInJSON;
}
/// --------- front end android
class Friend {
constructor(id, name){
this.id = id;
this.name = name;
}
}
// ajax call or volley call to server
var friendData = getFriendData();
// loop through the json data and create a friend per item
var friends = []; // array of Friend
for(var i=0; i<friendData.length; i++){
var data = friendData[i];
// serialize into real Friend object
friends.push(new Friend(data.id, data.name));
}
// now you have real friend data
console.log(friends);
// remove
removeFriendByID(24); //kim
console.log(friends);
// remove friend by ID
function removeFriendByID(friendID){
if (friendID != null) {
// find the friend the list
var friendToRemove = null;
for(var i=0; i<friends.length; i++){
if(friends[i].id == friendID){
friendToRemove = friends[i];
break; // break out the loop once found
}
}
// remove from array -- this is javascript, you'll need to use java methods on arrays
var index = friends.indexOf(friendToRemove);
friends.splice(index,1);
}
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.