Id from the DB, auto increment - BUG?

Hello everyone,
I’m playing around with ionic tabs sample app. In services.js I changed data to come from my remote JSON. Here’s the code:

angular.module(‘’, )


.factory(‘Friends’, function($http) {
var friends = ;

.success(function(data, status, headers,config){
console.log(‘data success’);
console.log(data); // object seems fine
.error(function(data, status, headers,config){
console.log(‘data error’);
friends =;

return {
all: function() {
return friends;
get: function(friendId) {
// Simple index lookup
return friends[friendId];

The JSON file returns:

{“id”:“1”,“name”:“John Thomas",“email”:"”},
{“id”:“2”,“name”:“Kim Cha",“email”:"”},
{“id”:“3”,“name”:“Tim Aloha",“email”:"”},
{“id”:“4”,“name”:“Ka Mie",“email”:"”},
{“id”:“5”,“name”:“Brad Lee",“email”:"”}

It all works except that, when I click a name from the list it jumps and shows the next entry’s details. So I guess it’s a bug or something? If I use another field and manually start id from 0 it all works just as expected.

What do you think?

a array begins with zero, if you call the item 1

"{"id":"1","name":"John Thomas","email":""}" 

it will show

"{"id":"2","name":"Kim Cha","email":""}"

because this is the second item in the array…

@maleeb Understand that. But don’t you think it’s kinda wrong to apply it here?

u can use like “return friends[friendId - 1];”, than its working

but if you have a id jump in your database, than its not working.
its better if u dont call the array with the id from the database