title: undefined error on accessing json/object from laravel controller to ajax call
body: <p>I am trying to manipulate an object/ json return from the controller in ajax jquery success method. </p>
  
  <p>My codes looks like this -</p>
  
  <p>On controller:</p>
  
  <pre><code>$product_code=$_GET['p_id'];        
  $productdata=Product::select('id','product_name','unit_measure','cost_price'
    )-&gt;where('product_code','=',$product_code)-&gt;get();    
      return $productdata;    //return object         
      return $productdata-&gt;toJson();//return json
  </code></pre>
  
  <p>On view(ajax call):</p>
  
  <pre><code>success: function(data){ 
    console.log(data);
    console.log(data["product_name"]);
    //for json [ console.log(data.product_name);
  },
  </code></pre>
  
  <p>Data has been received successfully but don't know why I am getting undefined error for accessing those data as above.
  Thanks in advance!</p>
  
  <p>This is what I am exactly getting when trying with json. Output in the console:</p>
  
  <pre><code>[{"id":3,"product_name":"computer network","unit_measure":"piece","cost_price":500}]
  undefined
  </code></pre>