function titleCase(str) {
var splitStr = str.toLowerCase().split(' ');
for (var i = 0; i < splitStr.length; i++) {
// You do not need to check if i is larger than splitStr length, as your for does that for you
// Assign it back to the array
splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);
}
// Directly return the joined string
return splitStr.join(' ');
}
function detectObjFromCurrentObj(obj){
var ObjIdx = '';
for (var prop in obj) {
if (typeof obj[prop] === "object") {
ObjIdx = prop;
}
}
return ObjIdx;
}
function detectSecTextFromCurrentObj(obj){
var STIdx = '';
for (var prop in obj) {
var regex = /^[a-zA-Z]{1}[0-9]{1}$/;
if (prop.includes('-st') || regex.test(prop) || prop == 'data') {
STIdx = prop;
if(obj[prop] == 'data'){
STIdx = 'data';
}
}
}
return STIdx;
}
function detectlevelCurrentObj(obj){
var STIdx = '';
for (var prop in obj) {
var regex = /^l{1}[0-9]{1}$/;
if(prop.includes('-st')){
STIdx = prop;
}else if(typeof obj[prop] === "object"){
STIdx = prop;
}else if (regex.test(prop)) {
STIdx = obj[prop];
if(prop == 'l4'){
STIdx = prop;
if(obj[STIdx] == 'data'){
STIdx = 'data';
}
}
// if(obj[prop] == 'data'){
// STIdx = 'data';
// }
}
}
// console.log(STIdx)
return STIdx;
}
function detectlvlHeading(obj){
var STIdx = '';
for (var prop in obj) {
var regex = /^[a-zA-Z]{1}[0-9]{1}$/;
if (prop == 'l2' || prop == 'l3') {
STIdx = prop;
}
}
return STIdx;
}
function sortObject(obj) {
var newObj = [];
for (var prop in obj) {
var objs = {};
if(typeof obj[prop] === "object"){
objs[prop] = obj[prop]
newObj.push(objs);
}else{
objs[prop] = obj[prop]
newObj.unshift(objs);
}
}
var fObj = {};
for (var prop1 in newObj) {
// console.log(prop1)
for (var prop2 in newObj[prop1]) {
//...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.