List of JavaScript Objects and Functions
-
Hi everyone,
I need to sort a JS array of objects like this { productId : "", product : "", price : 0, rebate : "", description: "" }
This is my code :
source.sort(function(a,b){
return a.product.toLocaleLowerCase().localCompare(b.product.toLocaleLowerCase())
});
When running, I got this error :
Starting /home/diarby/studio/qt/projects/build-test-Desktop_Qt_5_10_0_GCC_64bit-Debug/qtc_Desktop_Qt_5_10_0_GCC_64bit_Debug/install-root/test...
qrc:/datasource.js:1277: TypeError: Property 'localCompare' of object orange is not a functionHere, orange is the value of product property. and source is the array.
In the manual, it is said that ECMA-262 is supported and localCompare() is really a function.How can I do array sorting on basis of string objects ?
-
@Diarby said in List of JavaScript Objects and Functions:
qrc:/datasource.js:1277: TypeError: Property 'localCompare' of object orange is not a function
Here, orange is the value of product property. and source is the array.
In the manual, it is said that ECMA-262 is supported and localCompare() is really a function.Do you mean
localeCompare()
?