I'm trying to create the following thing, I couldn't find any success, let me know if there's a way :) I have 2 variables called text1 and text2, each one of them should represent a key inside an object and the value of the key will be the data variables.
In the beginning, the object will start as empty, and I need to create a function that will create that object inside the object as many times as need, it can be a case where the text will have more than 3 keys, for e.g. items.courses.lessons.assets.title etc.. so the function must be dynamic. notice that the function must check if the key already exists so it will not overwrite it if there is another text with the same starting keys (see example below)
const data1 = 'hello';
const text1 = 'lessons.first.title';
const data2 = 'hello there';
const text2 = 'lessons.first.description';
// how the end result should look like
const result = {
lessons: {
first: {
title: 'hello',
description: 'hello there',
},
},
};
Thanks! 😁😁