Proper order of Javascript methods

When I’m tagging methods on an array, is there an order that they should go in? For example, if I’m running arr.split(’ ‘)…but I also want to use .toLowerCase(), .trim(), join(’-’).
Should I put those before split(’ ')? Or after? Does it matter?

it matters, for example you can’t use split on an array, as it is a string method, so it needs to be a string you use it on.
toLowerCase and trim are string methods, you can’t use them on array.
and join is an array method - you can’t use it on a string

1 Like

if by any chance your question is either:

1) Are there any heirarchy conventions in accessing multiple properties of an Object prototype?

2) Can I put non-excluding properties together?

1: I do not think there are any such conventions/rules, but I could be wrong.

2: (see code block below)

const CASED_AND_SPACED = `         Hi, I am a sentence!       `;

console.log(`this: '${CASED_AND_SPACED.trim().toLowerCase()}',`);
console.log(`and this: '${CASED_AND_SPACED.toLowerCase().trim()}'`);
console.log(`will look the same.`);

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.