I have an HTML table that I'm storing task versions. The following examples of rows:
1.0 Task 1
1.1 Task 1.1
1.1.1 Task 1.1.1
1.1.2 Task 1.1.2
1.2.0 Task 1.2.0
1.2.1 Task 1.2.1
I want to be able to insert for example a new task after 1.1.1 so a new 1.1.2 will be added and the rest of the child values will increment:
1.0 Task 1
1.1 Task 1.1
1.1.1 Task 1.1.1
1.1.2 Task 1.1.2 - New entry
1.1.3 Task 1.1.3
1.2.0 Task 1.2.0
1.2.1 Task 1.2.1
I'm trying to figure out how to store this data in Javascript so I can easily add to or even delete anywhere in my structure.
Any ideas or suggestions?
Solution Using Maps
Just wanted to post after google trees and ran into maps
let map = new Map();
map.set('1.1.1', 'Task 1.1.1');
map.set('1.2.0', 'Task 1.2.0');
map.set('1.1', 'Task 1.1');
map.set('1.1.2', 'Task 1.1.2');
map.set('1.2.1', 'Task 1.2.1');
map.set('1.0', 'Task 1.0');
var mapAsc = new Map([...map.entries()].sort());
const elem = document.querySelector('#content');
let items = '';
for (let item of mapAsc.keys()) {
items += item + '\r\n ';
}
elem.innerText = items;
Output:
1.0
1.1
1.1.1
1.1.2
1.2.0
1.2.1
My JSFiddle enter link description here