Javascript vs. JSON Array of Objects: Fundamentals - Objects - Priceranges

Note: I do a lot of work with JSON objects using JSONATA ( Please keep that in mind regarding my question.

In the Price Range exercise, Mosh creates an array with the objects:

let priceRanges = [
    { label: '$', tooltip: 'Inexpensive', minPerPerson: 0, maxPerPerson: 10 },
    { label: '$$', tooltip: 'Moderate', minPerPerson: 11, maxPerPerson: 20 },
    { label: '$$$', tooltip: 'Expensive', minPerPerson: 21, maxPerPerson: 50 },

However, my answer

const priceRange = {
    low: {
        min: 0,
        max: 100,
        display: '$',
        toolTip: 'Inexpensive'
    medium: {
        min: 101,
        max: 200,
        display: '$$',
        toolTip: 'Moderate'
    high: {
        min: 201,
        max: 999,
        display: '$$$',
        toolTip: 'Expensive'

I make the assumption that the interpreter would imply that the object was an array of objects. This is assumption is based on JSON’s interpretation of the object, and the ability of JSONATA to count the array.


Is this a ‘you can do it either way’ thing or a specific concept that is trying to be taught?

I personally would lean more towards arrays when I need to perform actions that the high order functions or array methods give me out of the box, like sorting, filtering, mapping…etc, or when I need to think out how the data might scale. Right now your way of accessing members is pretty straight forward and readable. This example is a smaller set data.

Using arrays would mean I need to iterate over them and check for a value at an index, or some similar method.

Really depends on the situation and what makes sense to you.

I personally would rather work with priceRange.low.min, as opposed to priceRanges[0].minPerPerson.

I do not know what lesson this is for so I can not say what the lesson is about.