score:0

Accepted answer

put the check on type of value, if type is object then skip that part from rendering. by this way it will skip objects and arrays.

typeof([])  ==> 'object'

typeof({})  ==> 'object'

like this:

var data = {
    group: 'name',
    address: 'address',
    manager: 'john',
    products: [
        {
           electronic: 'laptop',
           team: 'awesome'
        }
    ]
}

object.entries(data).map(([key, val], index) => {
     if(typeof(val) != 'object') {
        console.log(key, val, index);   //return the span 
     }
     else null;
})

replace console.log(key, val, index) by <span key={key}> {key}: {value} </span>.

score:0

you can use filter before map:

var data = {
    'group': 'name',
    'address': 'address',
    'manager': 'john',
    'products': [
        {
            'electronic' 'laptop',
            'team': 'awesome
        }
    ]
}

return object.entries(data).filter(([key, value]) => {
  if (typeof value !== 'object' ) return 1;
}).map(([key, value]) => {
    <span key={key}> {key}: {value} </span>
});

here any key that is having value as object would be eliminated.

will return:

group: name
address: address
manager: john

score:1

try:

<div>
return object.entries(obj).map([key, value], i, arr){
    if (i !== arr.length - 1) {
      <span key={key}> {key}: {value} </span>
    }
}
</div>

score:2

get the number of keys in the object using arr.length as third parameter to the map function and compare with the index in the map function like below snippet. also you are returning the data incorrectly from map

var data = {
    group: 'name',
    address: 'address',
    manager: 'john',
    products: [
        {
        electronic: 'laptop',
        team: 'awesome'
        }
    ]
}
var len = object.keys(data).length;
object.entries(data).map(([key, val], index, arr) => {
     if(index !== arr.length - 1) {
     console.log(key, val, index);
     }
})

you code being

<div>
 {object.entries(obj).map([key, value], index, arr){
    if(index < arr.length) {
          return   <span key={key}> {key}: {value} </span>
    } 
}
</div>

Related Query

More Query from same tag