私の配列の最後の要素を取得するために.pop()関数を使用しようとしています(それは私のWebページに表示されます)。私は 配列の最後の要素を取得するJavaScriptが関数ではありません
var notif_count = data.pop();
が、私はエラーを取得する... Javascriptを/ jQueryの私はこれで少し苦労してるとかなり新しいです:
マイデータ「キャッチされない例外TypeError 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を取得しようとしている - 私はそれをどのように行うのですか?
EDIT:完全なコード例
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) –