0

I have a object parameter with a property and value like

$scope.chartOptions.response.items.count = { amazing: 8, amenities: 6, awesome: 7, beautiful: 15, better: 9, clean: 12, comfortable: 8, complaint: 6, definitely stay: 6, excellent: 11, friendly: 17, front desk: 8, good: 15, gorgeous: 6, great: 28, helpful: 11, nice: 15, perfect: 7, the best: 10, wonderful: 12 }

The array has value of 20 indexes. The array looks like

series[] = ["great", "friendly", "good", "beautiful", "nice", "wonderful", "clean", "excellent", "helpful", "the best", "better", "comfortable", "front desk", "amazing", "perfect", "awesome", "amenities", "complaint", "gorgeous", "definitely stay"]

I want to sort the object according to values in the array and store all the numerical values in a second array like series2[]= [28, 17, 15...] Is this possible using angularjs and javascript

0

1 Answer 1

1

Iterate the series with Array.map(), and get the value from count by the current string:

const count = { amazing: 8, amenities: 6, awesome: 7, beautiful: 15, better: 9, clean: 12, comfortable: 8, complaint: 6, 'definitely stay': 6, excellent: 11, friendly: 17, 'front desk': 8, good: 15, gorgeous: 6, great: 28, helpful: 11, nice: 15, perfect: 7, 'the best': 10, wonderful: 12 };
const series = ["great", "friendly", "good", "beautiful", "nice", "wonderful", "clean", "excellent", "helpful", "the best", "better", "comfortable", "front desk", "amazing", "perfect", "awesome", "amenities", "complaint", "gorgeous", "definitely stay"];


const sortedNumbers = series.map((str) => count[str]);

console.log(sortedNumbers);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.