This will do what you're trying:
public function getProductCategoriesArray()
{
$productcategories = ProductCategory::get()->pluck('name', 'name')->map(function($cat) {
return [];
});
return response()->json([
'productcategories' => $productcategories,
]);
}
The result will be an object with empty arrays.
{
productcategories: {
Category1: [],
Category2: [],
Category3: [],
}
}
In Javascript, an array can only have 0 -> xxx as keys, it's not like PHP where we have Indexed & Associative arrays, Associative arrays will always become objects when converted to javascript.