Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

How to get value in JavaScript array

I'm trying get a value inside a JavaScript array from the output of an AJAX request.

Ajax request:

$.ajax({
 url: "ajax-test.php",
 type: "POST",
 data: "sku=800270",
 dataType: "html"
 }).done(function(resposta) {
 console.log(resposta);
}

Ajax-Test.php:

$produto[] = array('sku' => $product->getSku(),
 'name' => $product->getName());
var_dump($produto[0]);

Returns:

array(6) {
 ["sku"]=>
 string(6) "000188"
 ["name"]=>
 string(80) "Cuba Gastronômica Aço Inoxidável para Buffet GN ×ばつ65mm (325x265mm) - 812-2"
}

I need to access the values inside the array, something like:

var sku = resposta["sku"]

In my tests if I try to print resposta["sku"] its giving me "undefined variable".

Answer*

Draft saved
Draft discarded
Cancel

lang-js

AltStyle によって変換されたページ (->オリジナル) /