.pop() 함수를 사용하여 배열의 마지막 요소를 얻으려고합니다. (웹 페이지에 표시되는 값입니다.) 내가 자바의 배열 .pop()의 마지막 요소를 가져 오는 것이 함수가 아닙니다.
var notif_count = data.pop();
내가 오류 ... 자바 스크립트/JQuery와 내가 이것에 조금 어려움을 겪고있어 상당히 새로운 해요 :
내 데이터 "catch되지 않는 형식 오류 data.pop는 함수가 아닙니다" 콘솔에서 다차원 배열처럼 보이지만 잘 모르겠습니다. 다음은 출력의 샘플입니다.
EDIT 2 - 출력은 여기에 표시된 문자가 포함 된 문자열입니다.
[
[
{
"_can_chaccess": true,
"_can_chown": true,
"_can_delete": true,
"_can_modify": true,
"_can_read": true,
"created_at": "Wed Jan 04 17:33:13 UTC 2017",
"created_by": 25206,
"created_by_user[login_name]": "[email protected]",
"created_by_user[person_name]": "Jamie Lowe",
"created_through": "Workbooks",
"created_through_reference": "",
"id": 117662,
"imported": false,
"key": "notifications",
"key10": "",
"key11": "",
"key12": "",
"key13": "",
"key14": "",
"key15": "",
"key16": "",
"key17": "",
"key18": "",
"key19": "",
"key2": "292801",
"key3": "47930",
"key4": "CASE-32109",
"key5": "",
"key6": "",
"key7": "",
"key8": "",
"key9": "",
"lock_version": 0,
"owner[login_name]": "[email protected]",
"owner[person_name]": "Jamie Lowe",
"owner_id": 25206,
"type": "Private::Automation::ApiData",
"updated_at": "Wed Jan 04 17:33:13 UTC 2017",
"updated_by": 25206,
"updated_by_user[login_name]": "[email protected]",
"updated_by_user[person_name]": "Jamie Lowe",
"value": ""
},
{
"_can_chaccess": true,
"_can_chown": true,
"_can_delete": true,
"_can_modify": true,
"_can_read": true,
"created_at": "Wed Jan 04 17:23:21 UTC 2017",
"created_by": 25206,
"created_by_user[login_name]": "[email protected]",
"created_by_user[person_name]": "Jamie Lowe",
"created_through": "Workbooks",
"created_through_reference": "",
"id": 117660,
"imported": false,
"key": "notifications",
"key10": "",
"key11": "",
"key12": "",
"key13": "",
"key14": "",
"key15": "",
"key16": "",
"key17": "",
"key18": "",
"key19": "",
"key2": "292801",
"key3": "47930",
"key4": "CASE-32106",
"key5": "",
"key6": "",
"key7": "",
"key8": "",
"key9": "",
"lock_version": 2,
"owner[login_name]": "[email protected]",
"owner[person_name]": "Jamie Lowe",
"owner_id": 25206,
"type": "Private::Automation::ApiData",
"updated_at": "Wed Jan 04 17:30:39 UTC 2017",
"updated_by": 25206,
"updated_by_user[login_name]": "[email protected]",
"updated_by_user[person_name]": "Jamie Lowe",
"value": ""
}
],
2
]
기본적으로 내가 바로 닫기 전에 배열의 끝에 숫자 2를 얻으려고] - 내가 어떻게해야합니까?
편집 : FULL 코드 예
var notif_count = data[1]; <!-- Last element in the array which is the count of notifications calculated server side by PHP -->
console.log(notif_count);
$('#count').text(notif_count);
[재현 할 수없는 (http://imgs.xkcd.com/comics/cnr.png) (크롬, FF). – ASDFGerte
방금 배열을 내 콘솔에 붙여 넣고'.pop()'를 성공적으로 호출했습니다. 'pop '이라고 부르는 데 사용하는 코드를 보여주세요 – Michael
이 여기에 있습니다 - [예제] (http://jsbin.com/kotadanigo/edit?js,console) –