I have a challenge where I need to extract items from an array obtained through a fetch request. The tricky part is that these arrays may have different keys, making it hard to predict them in advance. However, all of them share the 'created_by' key. Hence, I am looking for a solution that can dynamically render all values before the 'created_by' key.
Below is the code snippet I currently have using the render/map method, which is not functioning correctly:
return <div className="data-subContainer">
{resData.map(item => <span key={item.id}>{item[1.3]} - <b>{item[2]}</b></span>)}
</div>
Sample output of resData:
(10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {4: "X", 5: "X", 6: "05/16/2020", id: "4627", form_id: "3", post_id: null, date_created: "2020-05-16 05:27:50", date_updated: "2020-05-16 05:27:50", …}
1: {4: "X", 5: "X", 6: "05/14/2020", id: "4618", form_id: "3", post_id: null, date_created: "2020-05-14 13:50:32", date_updated: "2020-05-14 13:50:32", …}
(remaining data entries follow with similar structure)
Example highlighting the variance in key numbers:
1: "XX"
2: "XXXX"
3.2: ""
3.3: "XX"
3.4: ""
3.6: "X"
3.8: ""
4: "X"
(continuation of key-value pairs)
created_by: "X"
Different example demonstrating the inconsistency in key numbering:
1.2: ""
1.3: "X"
1.4: ""
1.6: "X"
1.8: ""
4: "X"
(remaining key-value pairs listed here)
created_by: "X"