Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I join a the string of array inside an array?

How could I join a string inside an array of array? I’m trying to remove the space between inside array.

This is the array sample.

[
  [ 'time' ],
  [ 'user full name' ],
  [ 'affected user' ],
  [ 'event context' ],
  [ 'component' ],
  [ 'event name' ],
  [ 'description' ],
  [ 'origin' ],
  [ 'ip address' ]
]

I’m trying this to become like this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[
  [ 'time' ],
  [ 'userfullname' ],
  [ 'affecteduser' ],
  [ 'eventcontext' ],
  [ 'component' ],
  [ 'eventname' ],
  [ 'description' ],
  [ 'origin' ],
  [ 'ipaddress' ]
]

This is my function i’m trying to run

const MakeArrayToSmall = (headerRow) => {
        let arrayToCheck = [];

        for (let i = 0; i < headerRow.length; i++) {
          let lowercaseLetter = headerRow[i].toLowerCase().split();
          arrayToCheck.push(lowercaseLetter)
        }
        return arrayToCheck
      
      };

      
      const samplearray = MakeArrayToSmall(headerRow)
      console.log(samplearray)

>Solution :

Loop the headerRow and then select the first element in the inner array and replace whitespaces with empty string headerRow[i][0].toLowerCase().replace(/\s/g, "")

const MakeArrayToSmall = (headerRow) => {
        let arrayToCheck = [];

        for (let i = 0; i < headerRow.length; i++) {
          let lowercaseLetter = headerRow[i][0].toLowerCase().replace(/\s/g, "");
          arrayToCheck.push(lowercaseLetter)
        }
        return arrayToCheck
      
      };
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading