Use case

Return the number of days that the issue spent in the previous status.

Expression

Create and configure a Smart field using this expression in Jira expression mode:

let statusChangelogs = issue.changelogs.filter(changelog => changelog.items.some(item => item.fieldId == 'status'));
statusChangelogs[0] ? (statusChangelogs[0].created.getTime() - (statusChangelogs[1] ? statusChangelogs[1].created : issue.created).getTime()) / (24*60*60*1000) : null